File transmission method, communication device and storage medium
Patent Information
- Application Number
- CN202410863452.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-29
- Publication Date
- 2024-08-23
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The traditional file transfer method relies on the ACK confirmation packet mechanism, which reduces the file transfer speed and affects the user experience especially in application scenarios that require high transfer speed.
By initializing the data packet sequence number bitmap, the data packet reception status is tracked in real time, the lost data packet is quickly located and retransmitted, avoiding waiting for ACK confirmation information, and directly writing the data packet to the target file.
It improves file transfer speed, reduces waiting time and unnecessary retransmissions, and ensures the integrity and sequence of file transfers.
Smart Images

Figure CN118540031A
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a file transmission method, communication equipment and storage medium. Background Art
[0002] With the rapid development of technology, the functions of electronic products are becoming increasingly rich, and most of these products are used with mobile applications (APPs) to achieve a more convenient and intelligent user experience. In this process, sending files to devices through APPs has become a common operation. Traditional file transfer methods usually rely on software or hardware ACK (Acknowledgment) confirmation packet mechanism to ensure that the data packet can reach the other end accurately and trigger a retransmission mechanism to correct transmission errors when necessary.
[0003] However, this file transfer method that relies on the ACK confirmation packet mechanism has significant shortcomings. Since it is necessary to wait for confirmation information before sending the next data packet, this method will reduce the overall speed of file transfer, thereby affecting the user experience. Especially in application scenarios with high transmission speed requirements, such as high-definition video streaming, real-time game interaction, etc., the reduction in transmission speed will directly lead to a decline in user experience. Summary of the invention
[0004] In view of this, the present application provides a file transmission method, a communication device and a storage medium to solve the technical problem that the overall speed of file transmission is reduced due to the ACK confirmation packet mechanism.
[0005] A first aspect of the present application provides a file transmission method, the method comprising: In response to receiving the file information sent by the sending end device, initializing the data packet sequence number bitmap according to the file information; Create a file buffer area and a target file for data writing; When receiving a data packet sent by the transmitting end device, updating the data packet sequence number bitmap according to the offset sequence number of the data packet; When the data packet is the last data packet received, determining the first target data packet that has not been received according to the updated data packet sequence number bitmap, and requesting the sending end device to retransmit the first target data packet; When receiving a data packet retransmitted by the sending end device, writing the retransmitted data packet into the file buffer area; When all data packets are received, the data packets in the file buffer area are written into the target file.
[0006] Optionally, initializing a data packet sequence number bitmap according to the file information includes: Calculating the total number of data packets to be received according to the file size in the file information; Determining the offset sequence number of the data packet to be received according to the total number; Initialize a data packet sequence number bitmap according to the offset sequence number.
[0007] Optionally, determining the first target data packet that has not been received according to the updated data packet sequence number bitmap includes: Get the target bit of the updated data packet sequence number bitmap as 0; Determine a target offset sequence number according to the target position; The data packet corresponding to the target offset sequence number is determined as the first target data packet that has not been received.
[0008] Optionally, when receiving the data packet sent by the transmitting end device, the method further includes: Check whether the receiving file has timed out; When a timeout is detected for receiving a file, relevant resources are released, and the sending device is notified of a failure in receiving the file; When no receiving file timeout is detected, whether receiving data packet timeout is detected; When a timeout of receiving a data packet is detected, it is determined whether the data packet is the last data packet received.
[0009] Optionally, the detection of whether the file reception timeout occurs includes: determining whether a first time difference between the current system time and the start time of receiving data packets is greater than a preset file reception timeout; when the first time difference is greater than the preset file reception timeout, a file reception timeout is detected; and when the first time difference is not greater than the preset file reception timeout, no file reception timeout is detected.
[0010] Optionally, the detection of whether the received data packet has timed out includes: determining whether a second time difference between the current system time and the time when the data packet is received is greater than a preset data packet timeout time; when the second time difference is greater than the preset data packet timeout time, a received data packet timeout is detected; and when the second time difference is not greater than the preset data packet timeout time, a received data packet timeout is not detected.
[0011] Optionally, before writing the retransmitted data packet into the file buffer area, the method further includes: Determining whether the retransmitted data packets arrive in order; When the retransmitted data packets arrive in order, the retransmitted data packets are directly written into the target file, and the data packets in the file buffer area whose offset sequence numbers are one greater than the offset sequence numbers of the retransmitted data packets and are continuous are written into the target file; When the retransmitted data packets arrive out of order, the step of writing the retransmitted data packets into the file buffer area is performed.
[0012] Optionally, the determining whether the retransmitted data packets arrive in sequence includes: Determine whether the offset sequence number of the retransmitted data packet is greater than the offset sequence number of the last received data packet by 1; When the offset sequence number of the retransmitted data packet is greater than the offset sequence number of the last received data packet by 1, it is determined that the retransmitted data packet arrives in order; When the offset sequence number of the retransmitted data packet is not greater than the offset sequence number of the last received data packet by 1, it is determined that the retransmitted data packet arrives out of order.
[0013] Optionally, the method further includes: When all data packets have not been completely received, determining whether the retransmitted data packet is the last data packet of the file; When the retransmitted data packet is the last data packet of the file, determining whether to request retransmission of all first target data packets; When retransmission of all first target data packets is not requested, retransmission of unreceived second target data packets is requested from the transmitting end device.
[0014] A second aspect of the present application provides a communication device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the file transfer method when executing the computer program.
[0015] A third aspect of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the file transfer method when executed by a processor.
[0016] The file transmission method, communication device and storage medium provided by the embodiment of the present application, when the receiving end device receives the file information sent by the sending end device, a data packet sequence number bitmap is initialized according to the file information, a file buffer area and a target file are created, and each time the receiving end device receives a data packet from the sending end device, the offset sequence number of the data packet is checked, and the data packet sequence number bitmap is updated according to the offset sequence number, so that the receiving end device can track in real time which data packets have been successfully received and which data packets have not been received. When the receiving end device determines that the received data packet is the last data packet, the lost data packet is quickly located according to the updated data packet sequence number bitmap, so as to send a request to the sending end device to retransmit these lost data packets. After receiving the retransmitted data packet sent by the sending end device, the receiving end device writes the retransmitted data packet to the file buffer area. When all data packets (including the originally received data packets and the retransmitted data packets) are successfully written to the file buffer area, the receiving end device takes these data packets out of the file buffer area and writes them into the target file, thereby ensuring that the target file stores complete and correctly sequenced file data. Since the receiving device does not need to wait for the ACK information of each data packet before continuing to receive the next data packet, the waiting time can be reduced, thereby improving the overall speed of file transfer. By updating the packet sequence number bitmap in real time and detecting lost packets, the receiving device can more accurately determine which packets need to be retransmitted, thereby reducing the number of unnecessary retransmissions. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a flowchart of a file transmission method shown in an embodiment of the present application; Figure 2 is a flowchart of another file transmission method shown in an embodiment of the present application; Figure 3 It is a structural diagram of a communication device shown in an embodiment of the present application. DETAILED DESCRIPTION
[0018] The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to be used as limitations to the present application. As used in the specification of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear indication to the contrary in the context. It should also be understood that the term "and / or" used in the present application refers to any or all possible combinations including one or more listed items.
[0019] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
[0020] The file transmission method provided by the embodiment of the present invention is executed by a communication device, and accordingly, the file transmission apparatus runs in the communication device.
[0021] In order to more clearly understand the inventive concept of the present application, the application scenario of the present application is described below with examples.
[0022] Assume that the first communication device needs to remotely transmit a file to the second communication device. Before the transmission, the file is divided into multiple small data packets for transmission. In the traditional method, the first communication device sends the first data packet to the second communication device through the network, and the second communication device sends an ACK (Acknowledgment) confirmation packet to the first communication device after correctly receiving the first data packet. Then, the first communication device sends the second data packet to the second communication device through the network, and the second communication device sends an ACK (Acknowledgment) confirmation packet to the first communication device after correctly receiving the second data packet. The first communication device sends the third data packet to the second communication device through the network, and so on, until all data packets are sent. It can be seen that this file transmission method that relies on the ACK confirmation packet mechanism needs to wait for confirmation information before sending the next data packet, which reduces the overall speed of file transmission.
[0023] This application first cancels the ACK check at the hardware level of the first communication device and the second communication device through the hardware communication setting between the first communication device and the second communication device. That is, when the first communication device can continuously send data packets to the second communication device, there is no need to wait for the ACK confirmation packet fed back by the second communication device. This application secondly detects and corrects data packet loss or errors caused by hardware link communication problems by adopting software packet verification and packet replenishment mechanisms, thereby increasing the file transmission speed without sacrificing transmission reliability, thereby improving user experience.
[0024] For the convenience of the following description, the first communication device that sends the data packet is referred to as a sending device (eg, a remote device or a server), and the second communication device that receives the data packet is referred to as a receiving device.
[0025] Figure 1 The flowchart of a file transmission method provided by an embodiment of the present invention includes the following steps.
[0026] S101, in response to receiving file information sent by a sending end device, initializing a data packet sequence number bitmap according to the file information.
[0027] In network transmission, different network types may have different transmission characteristics. Splitting a file into multiple data packets can ensure that the file can be smoothly transmitted in different types of networks. If a data packet is lost or damaged during the transmission process, only the data packet needs to be retransmitted instead of the entire file. Therefore, the sending device splits the file to be transmitted into multiple data packets and sends them to the receiving device.
[0028] Before sending a data packet to a receiving device, the sending device first sends file information to the receiving device. The file information may include, but is not limited to, key parameters such as the total size of the file to be transmitted and the size of each data packet.
[0029] After receiving the file information sent by the sending device, the receiving device initializes the data packet sequence number bitmap according to the file information. The data packet sequence number bitmap is a data structure used to track or manage the data packet sequence number. Each data packet has a unique sequence number, and the bitmap is used to quickly determine whether a data packet with a sequence number has been received.
[0030] In an optional implementation, initializing the data packet sequence number bitmap according to the file information includes: Calculating the total number of data packets to be received according to the file size in the file information; Determining the offset sequence number of the data packet to be received according to the total number; Initialize a data packet sequence number bitmap according to the offset sequence number.
[0031] The initialized packet sequence number bitmap is a data structure in which each bit represents a specific information or status. During the packet transmission process, the bitmap is used to record which packets have been received and which packets have not been received.
[0032] When the sending device sends a data packet to the receiving device, both parties agree in advance on a fixed size of the data packet for each transmission (for example, 256 bytes). Fixed-size data packets can improve transmission efficiency. Since both the sending device and the receiving device know the size of each data packet, both parties can manage memory and buffers more effectively. After receiving the file information, the receiving device obtains the file size from the file information and calculates the total number of data packets that need to be transmitted / received based on the file size and the fixed size.
[0033] Each data packet includes metadata and actual data content. The metadata includes the offset number of the data packet in the file to be transmitted. Each data packet has a unique offset number that identifies the position of the data packet in the file. When the receiving device receives all the data packets, it can sort them according to the offset number of each data packet, so as to combine all the data packets into a complete file. The data content is part of the file to be transmitted. Each data packet includes data of a fixed size, which ensures the integrity of the data. When the receiving device receives all the data packets and reassembles them, it can ensure that no data packets are lost or damaged.
[0034] The size of the data packet sequence number bitmap depends on the range of the offset sequence number. If the range of the data packet sequence number is 0 to N, then the data packet sequence number bitmap requires N+1 bits to represent the offset sequence numbers of all data packets. During initialization, all bits in the data packet sequence number bitmap are set to 0 by default, indicating that data packets have not yet been received. Each bit in the data packet sequence number bitmap corresponds one-to-one to the offset sequence number. For example, assuming that the size of the file to be transmitted is 10243 bytes and the fixed size of the data packet is 256 bytes, the total number of data packets to be received / transmitted is 41, the offset sequence number of the data packet is from 0 to 40, and the data packet sequence number bitmap has 41 bits.
[0035] Through the above optional implementation, by initializing a bitmap that corresponds to the offset sequence number of the data packet, it is possible to accurately track which data packets have been received and which data packets have not been received, which helps to ensure the integrity and reliability of the data. The bitmap data structure allows the receiving device to store data packet reception status information in a very compact manner. Compared with other data structures (such as lists or arrays), bitmaps use less memory space, which is conducive to resource optimization.
[0036] When the receiving device initializes the data packet sequence number bitmap, it also initializes the following parameters: FileSize: The size of the file to be received, in bytes; CurTime: current system time; AcceptTime: the time when the data packet is received; PacetTimeoutFlag: The data packet timeout flag is sent only once each time; FileMap: data packet sequence number bitmap, each data packet offset number corresponds to a bit in the bitmap; MaxPage: The total number of data packets to be received. Since the offset sequence number of the data packet starts from 0, the maximum offset sequence number of the data packet is MaxPage-1; PrePage: The maximum offset sequence number that has been received; WritePage: The offset number of the data packet that has been written to the target file; CurPage: the offset sequence number of the currently received data packet; RequestAllPacketFlag: A flag that requests retransmission of a data packet. After the receiving device receives the last data packet, it requests the sending device to retransmit all data packets with offset sequence numbers that have not been received.
[0037] It should be noted that during initialization, the offset sequence number PrePage received last time is -1, the time AcceptTime of receiving the previous data packet is the current system time, PacetTimeoutFlag = 0, WritePage = -1, RequestAllPacketFlag = 0. When PrePage = MaxPage-1, it indicates that the data packet with the last offset sequence number has been received.
[0038] S102, creating a file buffer area and a target file for data writing.
[0039] During the data packet transmission process, there may be packet loss problems, which may cause the received data packets to appear out of order. Therefore, it is necessary to add a buffer area to ensure that the data packets are written to the target file according to the correct offset sequence number, thereby ensuring the integrity and reliability of the file.
[0040] S103: When receiving a data packet sent by the transmitting end device, update the data packet sequence number bitmap according to the offset sequence number of the data packet.
[0041] When a data packet is received, the offset sequence number and actual data content of the data packet are parsed. As the data packet is received, the data packet sequence number bitmap FileMap is updated according to the offset sequence number CurPage of the data packet. Specifically, according to the offset sequence number CurPage of the data packet, the corresponding bit in the data packet sequence number bitmap FileMap is updated to 1, indicating that the data packet has been received. For example, assuming that the offset sequence number of the data packet is 4, the 5th bit in the data packet sequence number bitmap is updated to 1, indicating that the data packet with an offset sequence number of 4 (that is, the 5th data packet in the file) has been received. In this way, by subsequently scanning the updated data packet sequence number bitmap, you can check which data packets have been received (bits are 1) and which data packets have not been received (bits are 0). If all bits in the bitmap are 1, it means that all data packets have been successfully received.
[0042] When receiving a data packet sent by the sending device, the receiving device also needs to update the parameters CurTime and AcceptTime to the current system time. The current system time is the current time displayed by the internal clock in the operating system of the receiving device that records events and times.
[0043] In an optional implementation, when receiving the data packet sent by the transmitting end device, the method further includes: Check whether the receiving file has timed out; When a timeout is detected for receiving a file, relevant resources are released, and the sending device is notified of a failure in receiving the file; When no receiving file timeout is detected, whether receiving data packet timeout is detected; When a timeout of receiving a data packet is detected, it is determined whether the data packet is the last data packet received.
[0044] During the file transfer process, if the receiving device fails to receive all the data packets of the file within the preset time range, it is considered that the file reception timeout. During the data packet reception process, if the receiving device fails to receive a data packet within the preset time range, it is considered that the data packet reception timeout.
[0045] When receiving a data packet sent by the sending device, the receiving device starts a timer to track the progress of receiving the entire file. If the timer reaches the preset receiving file timeout and the file is still not completely received, it is determined that the receiving file has timed out. When the receiving file timeout is detected, the receiving device releases all resources related to file reception, such as memory, file handles, etc., to avoid resource waste. At the same time, the receiving device deletes the created target file and notifies the sending device of the failure to receive the file through a certain communication mechanism (such as an error message in the TCP / IP protocol) so that the sending device can take appropriate remedial measures (such as resending the file).
[0046] When receiving data packets, the receiving device sets a timer for each data packet. If the timer of a data packet reaches the preset receiving data packet timeout time and the data packet has not arrived, it is determined that the receiving data packet has timed out.
[0047] When a received data packet timeout is detected, the receiving device needs to determine whether the data packet is the last data packet received. If the receiving device directly requests retransmission without determining whether the data packet is the last data packet received after detecting a received data packet timeout, unnecessary retransmission operations may result. By determining whether the data packet is the last data packet received, the receiving device can more accurately determine the data packet that needs to be retransmitted, thereby optimizing resource usage and improving transmission efficiency.
[0048] In the above optional implementation, during the file transmission process, by detecting the timeout of receiving the file and the timeout of receiving the data packet, the receiving end device can promptly detect whether the network conditions have changed (such as network congestion, unstable signal, etc.), avoid abnormal conditions in the file transmission, and thus improve the reliability of the file transmission. In addition, when the timeout of receiving the file and / or the timeout of receiving the data packet are detected, they can be processed in a timely manner to avoid the waste of resources and inefficiency caused by long waiting time.
[0049] In an optional implementation, the detecting whether the receiving of the file has timed out includes: Determine whether a first time difference between the current system time and the time when the data packet starts to be received is greater than a preset file receiving timeout time; When the first time difference is greater than the preset file receiving timeout period, a file receiving timeout is detected; When the first time difference is not greater than the preset file receiving timeout period, no file receiving timeout is detected.
[0050] The system current time (CurTime) refers to the current time point of the system, which is provided by the clock on the receiving device. During the file receiving process, the receiving device obtains the current time (CurTime) in real time.
[0051] The start time of receiving data packets refers to the time when the receiving device receives the first data packet when it starts receiving the file. When the receiving device starts receiving the file and successfully receives the first data packet, the system records the current time (AcceptTime) as the start time of file reception. The start time of receiving data packets is used as the starting reference point of the file reception process.
[0052] The preset file reception timeout is a preset time threshold used to determine whether the file reception exceeds an acceptable time range.
[0053] The receiving device calculates the difference between the current time (CurTime) and the time when the data packet starts to be received (AcceptTime) to obtain a first time difference, and then detects whether the file reception timeout occurs according to the relationship between the first time difference and the preset file reception timeout period.
[0054] In an optional implementation, the detecting whether the received data packet times out includes: Determine whether a second time difference between the current system time and the time when the data packet is received is greater than a preset data packet timeout time; When the second time difference is greater than the preset data packet timeout time, a timeout of receiving the data packet is detected; When the second time difference is not greater than the preset data packet timeout period, no timeout of receiving the data packet is detected.
[0055] The time when a data packet is received (AcceptTime) refers to the time when the receiving device successfully receives a data packet. Every time the receiving device successfully receives a data packet, the current system time is recorded as the receiving time of the data packet.
[0056] The preset data packet timeout period is a preset time threshold used to determine whether the time interval for receiving data packets exceeds an acceptable range.
[0057] The receiving device calculates the difference between the current time and the time when the data packet was received most recently to obtain a second time difference, thereby detecting whether the received data packet has timed out based on the relationship between the second time difference and a preset data packet timeout period.
[0058] It should be understood that since the receive file timeout is a higher-level timeout mechanism that focuses on the completion time of the entire file transfer, while the receive data packet timeout focuses on the transmission interval between individual data packets, the present application first detects whether the receive file has timed out, and then detects whether the receive data packet has timed out. If the receive data packet timeout is detected first, retransmission requests may be frequently triggered due to the loss or delay of a single data packet, resulting in unnecessary network traffic and server load. Detecting whether the receive file has timed out first ensures that further action is taken only when there is a problem with the entire file transfer, thereby optimizing resource usage.
[0059] S104: When the data packet is the last data packet received, determine the first target data packet that has not been received according to the updated data packet sequence number bitmap, and request the sending end device to retransmit the first target data packet.
[0060] When the receiving device receives a data packet, it updates the data packet sequence number bitmap according to the offset sequence number of the data packet and sets the corresponding bit to 1, indicating that the data packet has been successfully received. When the receiving device determines that the data packet is the last data packet received, it checks the data packet sequence number bitmap to determine which data packets have not been received before the last data packet (i.e., the data packets whose corresponding positions in the bitmap are 0).
[0061] In an optional implementation, after determining the lost data packets, the receiving device will identify the first lost data packet (i.e., the lost data packet with the smallest offset sequence number), and this data packet will become the target of the retransmission request, i.e., the first target data packet. The receiving device will send a retransmission request to the sending device, and the retransmission request includes the offset sequence number of the first target data packet. After receiving the retransmission request, the sending device will resend the first target data packet. After retransmitting the first target data packet, the receiving device will continue to check subsequent data packets (if any). If any of the subsequent data packets are lost, the receiving device will continue to request retransmission in the same manner.
[0062] In another optional implementation, after determining the lost data packets, the receiving device identifies all the lost data packets as the target of the retransmission request, i.e., the first target data packets. The receiving device sends a retransmission request to the sending device, and the retransmission request includes the offset sequence numbers of all the first target data packets. After receiving the retransmission request, the sending device can retransmit the first target data packets one by one according to the offset sequence numbers.
[0063] In an optional implementation, determining the first target data packet that has not been received according to the updated data packet sequence number bitmap includes: Get the target bit of the updated data packet sequence number bitmap as 0; Determine a target offset sequence number according to the target position; The data packet corresponding to the target offset sequence number is determined as the first target data packet that has not been received.
[0064] After each successful receipt of a data packet, the receiving device updates the data packet sequence number bitmap. After updating the data packet sequence number bitmap, the receiving device traverses the entire data packet sequence number bitmap and searches for a value of 0 as the target bit. The target bit corresponds to the offset sequence number of the data packet that has not yet been received. The data packet corresponding to the target offset sequence number is identified as a data packet that has not been received (the first target data packet).
[0065] Exemplarily, assume that the size of the data packet sequence number bitmap is 16 bits. The receiving device successfully receives data packets with sequence numbers 0, 1, 3, 5, 6, 7, 8, 9, 11, 12, 13, 14, and 15, and updates the bitmap. At this time, the bits with sequence numbers 2, 4, and 10 in the data packet sequence number bitmap will be 0. The receiving device traverses the data packet sequence number bitmap and finds that the bits with sequence numbers 2, 4, and 10 are 0 as the target offset sequence numbers. Then the data packets with offset sequence numbers 2, 4, and 10 are the first target data packets that have not been received.
[0066] The above optional implementation method can ensure that the receiving device can eventually obtain a complete data file or data stream by accurately identifying and requesting retransmission of lost data packets. Requesting retransmission of only lost data packets instead of the entire file can save network bandwidth and transmission time, and improve the efficiency of data transmission.
[0067] S105, when receiving a data packet retransmitted by the sending end device, writing the retransmitted data packet into the file buffer area.
[0068] Before writing a data packet to the file buffer area, you can verify whether the offset sequence number of the data packet is legal or as expected. For example, you can check whether the offset sequence number is within the expected offset sequence number range, or whether there is a missing offset sequence number. If the offset sequence number of the data packet is legal and not repeated, the data packet is added to the file buffer area. The file buffer area can be a dictionary, a list, or other suitable data structure. If the file buffer area is a dictionary, you can use the offset sequence number of the data packet as the key and the actual data content of the data packet as the value; if the file buffer area is a list, you can use the offset sequence number and the actual data content of the data packet.
[0069] In an optional embodiment, before writing the retransmitted data packet into the file buffer area, the method further includes: Determining whether the retransmitted data packets arrive in order; When the retransmitted data packets arrive in order, the retransmitted data packets are directly written into the target file, and the data packets in the file buffer area whose offset sequence numbers are one greater than the offset sequence numbers of the retransmitted data packets and are continuous are written into the target file; When the retransmitted data packets arrive out of order, the step of writing the retransmitted data packets into the file buffer area is performed.
[0070] In the normal file transfer process, the sending device usually sends data packets in the ascending order of the offset sequence number, and the data packets arrive at the receiving device in the order in which they are sent (that is, the ascending order of the offset sequence number). After receiving the data packet, the receiving device determines whether the offset sequence number of the currently received data packet is 1 greater than the offset sequence number of the last received data packet to determine whether the currently received data packet has arrived in order. If the offset sequence number of the currently received data packet is 1 greater than the offset sequence number of the last received data packet, it is considered that the currently received data packet has arrived in order. If the offset sequence number of the currently received data packet is not 1 greater than the offset sequence number of the last received data packet, it is considered that the currently received data packet has not arrived in order.
[0071] The above optional implementation method determines whether the data packet arrives in order, and decides whether to write the data packet directly into the target file or into the file buffer area according to the determination result. When the data packet arrives in order, the data packet is written directly into the file without performing additional sorting or caching operations, thereby reducing the consumption of computing resources and improving processing efficiency. At the same time, the risk of the data packet being accidentally overwritten or lost while waiting in the file buffer area can be reduced. When the data packet arrives out of order, the data packet is written into the file buffer area, so that the data packet arriving out of order can wait in the file buffer area until it can be written into the file in the correct order, thereby ensuring that the data written into the file is complete and in order, avoiding file damage or data inconsistency problems caused by the disorder of the data packet. In addition, in the file buffer area, the data packets arriving out of order can be rearranged to ensure that these data packets can be processed in the correct order.
[0072] In an optional implementation, the determining whether the retransmitted data packets arrive in order includes: Determine whether the offset sequence number of the retransmitted data packet is greater than the offset sequence number of the last received data packet by 1; When the offset sequence number of the retransmitted data packet is greater than the offset sequence number of the last received data packet by 1, it is determined that the retransmitted data packet arrives in order; When the offset sequence number of the retransmitted data packet is not greater than the offset sequence number of the last received data packet by 1, it is determined that the retransmitted data packet arrives out of order.
[0073] When obtaining the offset sequence number CurPage of the data packet, the receiving device can also compare the offset sequence number CurPage of the data packet with the maximum offset sequence number PrePage that has been received. If CurPage is greater than PrePage, it means that the receiving device has received a new data packet that has not been processed yet, then PrePage is updated to CurPage to reflect the latest reception progress. Otherwise, if CurPage is less than or equal to PrePage, it means that the receiving device has received a duplicate data packet (due to network retransmission or other reasons), then PrePage remains unchanged.
[0074] In other implementations, if CurPage is less than or equal to PrePage, the receiving device may ignore the data packet to avoid repeated processing, thereby helping to reduce unnecessary consumption of computing resources and improve system efficiency.
[0075] S106, when all the data packets are received, the data packets in the file buffer area are written into the target file.
[0076] Before writing all data packets in the file buffer area to the target file, the receiving device may check the integrity of the data packets by comparing the offset sequence number, checksum or other integrity verification mechanisms of the data packets to ensure that no data packets are damaged or tampered with during transmission.
[0077] If data packets arrive out of order due to network delays or out of order during transmission, the receiving device needs to sort the data packets according to the offset sequence number before writing them into the target file to ensure that the data packets are written into the file in the correct order.
[0078] The receiving device reads data packets from the file buffer area and writes the contents of the read data packets to the target file. After each data packet is written, the file pointer is updated to ensure that the next data packet is written to the correct location. The reading and writing process is repeated until all data packets in the file buffer area are written to the target file. After all data packets are successfully written to the target file, the target file is closed to ensure that all data is correctly saved.
[0079] Optionally, after completing writing of the target file, the receiving device may release all resources related to the file transfer, such as memory buffers, file handles, etc.
[0080] In an optional embodiment, the method further comprises: When all data packets have not been completely received, determining whether the retransmitted data packet is the last data packet of the file; When the retransmitted data packet is the last data packet of the file, determining whether to request retransmission of all first target data packets; When retransmission of all first target data packets is not requested, retransmission of unreceived second target data packets is requested from the transmitting end device.
[0081] When the receiving device detects that a data packet is lost or timed out, it will request the sending device to retransmit the lost data packet. In this process, the receiving device needs to track which data packets have been requested to be retransmitted and which data packets are retransmitted.
[0082] When receiving a retransmitted data packet, the receiving device first checks whether the data packet is the last data packet of the file. If the retransmitted data packet is the last data packet of the file, the receiving device further checks whether the retransmission of all lost first target data packets has been requested by checking the internal data packet sequence number bitmap or retransmission request record. If the receiving device determines that the retransmission of all first target data packets has not been requested, it will continue to request the sending device to retransmit these data packets. If the retransmission of all first target data packets has been requested, but there are still other data packets (i.e., second target data packets) that have not been received, the receiving device will request the sending device to retransmit these data packets.
[0083] For example, assume that the receiving device loses data packets A, B, and C when receiving a file, where C is the last data packet of the file. The receiving device first requests retransmission of data packet A. If the receiving device receives retransmission of data packet C (the last data packet) before or after receiving retransmission of data packet A, it will check whether retransmission of data packet B has been requested. If retransmission of data packet B has not been requested, the receiving device will request retransmission of data packet B from the sending device.
[0084] The above optional implementation method improves the efficiency and reliability of file transmission by finely controlling the retransmission process. For data packets that have been successfully received or data packets that have been requested for retransmission, there is no need to request retransmission again, which can reduce the occupation of network bandwidth and improve the utilization of network resources.
[0085] The inventive concept of the present application is described below in conjunction with the initialized parameters.
[0086] Step 1: After the receiving device receives the file information sent by the sending device, it obtains the file size FileSize and can calculate the offset number of the data packet. According to the offset number, all bits in the data packet number bitmap are initialized to 0, the file number PrePage received last time is -1, the time AcceptTime of receiving the previous data packet is the current system time, PacetTimeoutFlag=0, WritePage=-1, RequestAllPacketFlag=0. Create a file buffer area and the target file for data writing.
[0087] Step 2: When CurTime-AcceptTime is greater than the preset file receiving timeout (e.g., 10S), relevant resources are released, the sending end device is notified of the failure to receive the file, the created target file is deleted, and the file receiving process is exited. Otherwise, when CurTime-AcceptTime is not greater than the preset file receiving timeout, the third step is performed.
[0088] Step 3: If PacetTimeoutFlag is equal to 1, jump to step 5; when CurTime-AcceptTime is greater than the preset data packet timeout (for example, 2S, if no data packet is received within 2S, it is considered that the communication may be lost, or the sending device believes that the data packet has been transmitted, but some data packets are lost due to communication), jump to step 4.
[0089] Step 4: Set PacetTimeoutFlag=1. When PrePage is less than MaxPage-1, the sending device will be requested to retransmit the data packet with offset number PrePage+1. Otherwise, FileMap will be checked and the sending device will be requested to retransmit the data packet with offset number corresponding to all bits in the data packet number bitmap that are 0.
[0090] Step 5: Check whether the data packet is received. If not, jump to step 2; otherwise, set PacetTimeoutFlag=0, AcceptTime=CurTime, and jump to step 6.
[0091] Step 6: If the bit of the offset sequence number CurPage corresponding to FileMap is already 1, indicating that the corresponding data packet has been received before, then ignore this data packet and jump to step 2.
[0092] Step 7: If CurPage=WritePage+1, write this data packet into the target file, and write the consecutive data packets starting from the offset number CurPage+1 in the file buffer area into the target file in sequence, and delete the data packets written into the target file from the file buffer area; otherwise, write them into the file buffer area.
[0093] Step 8: If CurPage>PrePage+1, request the data packet with offset number from PrePage+1 to CurPage-1 from the sending device; if CurPage>PrePage, set PrePage=CurPage; and set the bit of offset number CurPage corresponding to FileMap to 1 to mark that this data packet has been received.
[0094] Step 9: If all data packets are received, write the data packets in the file buffer area into the target file in ascending order of offset numbers, clean up the file buffer area, and exit the process of receiving files; otherwise, jump to step 10.
[0095] Step 10: If PrePage+1=MaxPage and RequestAllPacketFlag=0, set RequestAllPacketFlag=1, check FileMap, and request the sending device to retransmit the data packets with offset numbers corresponding to all bits that are 0 in the data packet sequence number bitmap; otherwise, jump to step 2.
[0096] Figure 2 The flowchart of another file transmission method provided by an embodiment of the present invention is as follows. The file transmission method specifically includes the following steps.
[0097] S201, receiving file information.
[0098] S202, initializing a data packet sequence number bitmap according to the file information, and creating a file buffer area and a target file for data writing.
[0099] Create a bitmap based on the file size and clear the bitmap to 0.
[0100] S203, when receiving a data packet, detecting whether the receiving file has timed out.
[0101] When a timeout in receiving the file is detected, S204 is executed; when a timeout in receiving the file is not detected, S205 is executed.
[0102] S204, releasing related resources and notifying the sending end device that the file reception failed.
[0103] S205, detecting whether the received data packet times out.
[0104] When a timeout of receiving a data packet is detected, S206 is executed; when a timeout of receiving a data packet is not detected, S208 is executed.
[0105] S206, determining whether the data packet is the last data packet received.
[0106] When the data packet is the last data packet received, S207 is executed; when the data packet is not the last data packet received, S208 is executed.
[0107] S207, requesting the sending end device to retransmit the target data packet that has not been received.
[0108] When the data packet is the last data packet received, the first target data packet that has not been received is determined according to the updated data packet sequence number bitmap, and a request is made to the sending end device to retransmit the first target data packet.
[0109] S208, determining whether a retransmitted data packet is received.
[0110] When no data packet retransmitted by the transmitting device is received, S203 is executed; when a data packet retransmitted by the transmitting device is received, S209 is executed.
[0111] S209, determining whether the retransmitted data packets arrive in sequence.
[0112] When the retransmitted data packets arrive in order, S210 is executed; when the retransmitted data packets arrive out of order, S211 is executed.
[0113] S210, directly write the retransmitted data packet into the target file, and write the data packets in the file buffer area whose offset sequence numbers are 1 greater than the offset sequence numbers of the retransmitted data packet and are continuous into the target file.
[0114] S211, writing the retransmitted data packet into the file buffer area.
[0115] S212, determining whether all data has been received.
[0116] When all the data packets are received, S213 is executed; when all the data packets are not received, S214 is executed.
[0117] S213, writing the data packets in the file buffer area into the target file.
[0118] S214, determining whether the retransmitted data packet is the last data packet of the file.
[0119] When the retransmitted data packet is not the last data packet of the file, execute S203; when the retransmitted data packet is the last data packet of the file, execute S215.
[0120] S215, determining whether to request retransmission of all first target data packets.
[0121] When retransmission of all first target data packets is requested, S203 is executed; when retransmission of all first target data packets is not requested, S216 is executed.
[0122] S216, requesting the sending end device to retransmit the second target data packet that has not been received.
[0123] It should be understood that the Figure 1 The various variations and specific embodiments in the related description of the file transmission method are also applicable to the attached Figure 2 And file transmission method thereof, by attaching Figure 1 A detailed description of the file transmission method thereof will be apparent to those skilled in the art. Figure 2 The implementation process of the file transmission method thereof will not be described in detail here for the sake of brevity of the specification.
[0124] When the receiving device receives the file information sent by the sending device, the application first initializes a data packet sequence number bitmap according to the file information. During initialization, all bits in the data packet sequence number bitmap are set to the unreceived state. Create a file buffer area and a target file. The file buffer area is used to temporarily store the received data packets until all data packets are received; the target file is used to store complete and correctly ordered file data. Whenever the receiving device receives a data packet from the sending device, it checks the offset sequence number of the data packet and updates the data packet sequence number bitmap according to the offset sequence number, so that the receiving device can track in real time which data packets have been successfully received and which data packets have not been received. When the receiving device determines that the last data packet has been received, it quickly locates the lost data packets (data packets that have not been received). Then, a request is sent to the sending device to request the retransmission of these lost data packets. After receiving the retransmitted data packets sent by the sending device, the receiving device writes to the file buffer area. When all data packets (including originally received data packets and retransmitted data packets) are successfully written to the file buffer area, the receiving device will take these data packets out of the file buffer area in the correct order and write them to the target file, thus ensuring that the target file stores complete and correctly sequenced file data.
[0125] Since the receiving device does not need to wait for the ACK information of each data packet before continuing to receive the next data packet, the waiting time can be reduced, thereby improving the overall speed of file transfer. By updating the packet sequence number bitmap in real time and detecting lost packets, the receiving device can more accurately determine which packets need to be retransmitted, thereby reducing the number of unnecessary retransmissions.
[0126] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the following steps are performed: In response to receiving the file information sent by the sending end device, initializing the data packet sequence number bitmap according to the file information; Create a file buffer area and a target file for data writing; When receiving a data packet sent by the transmitting end device, updating the data packet sequence number bitmap according to the offset sequence number of the data packet; When the data packet is the last data packet received, determining the first target data packet that has not been received according to the updated data packet sequence number bitmap, and requesting the sending end device to retransmit the first target data packet; When receiving a data packet retransmitted by the sending end device, writing the retransmitted data packet into the file buffer area; When all data packets are received, the data packets in the file buffer area are written into the target file.
[0127] In an optional implementation, when the computer program is executed by a processor, initializing the data packet sequence number bitmap according to the file information includes: Calculating the total number of data packets to be received according to the file size in the file information; Determining the offset sequence number of the data packet to be received according to the total number; Initialize a data packet sequence number bitmap according to the offset sequence number.
[0128] In an optional embodiment, when the computer program is executed by a processor, determining the first target data packet that has not been received according to the updated data packet sequence number bitmap includes: Get the target bit of the updated data packet sequence number bitmap as 0; Determine a target offset sequence number according to the target position; The data packet corresponding to the target offset sequence number is determined as the first target data packet that has not been received.
[0129] In an optional implementation, when receiving a data packet sent by the transmitting end device, the computer program further implements when executed by the processor: Check whether the receiving file has timed out; When a timeout is detected for receiving a file, relevant resources are released, and the sending device is notified of a failure in receiving the file; When no receiving file timeout is detected, whether receiving data packet timeout is detected; When a timeout of receiving a data packet is detected, it is determined whether the data packet is the last data packet received.
[0130] In an optional implementation, when the computer program is executed by a processor, the detecting whether the receiving file has timed out includes: Determine whether a first time difference between the current system time and the time when the data packet starts to be received is greater than a preset file receiving timeout time; When the first time difference is greater than the preset file receiving timeout period, a file receiving timeout is detected; When the first time difference is not greater than the preset file receiving timeout period, no file receiving timeout is detected.
[0131] In an optional implementation, when the computer program is executed by a processor, the method of detecting whether a received data packet has timed out includes: Determine whether a second time difference between the current system time and the time when the data packet is received is greater than a preset data packet timeout time; When the second time difference is greater than the preset data packet timeout time, a timeout of receiving the data packet is detected; When the second time difference is not greater than the preset data packet timeout period, no timeout of receiving the data packet is detected.
[0132] In an optional implementation, before writing the retransmitted data packet into the file buffer area, the computer program further implements when executed by the processor: Determining whether the retransmitted data packets arrive in order; When the retransmitted data packets arrive in order, the retransmitted data packets are directly written into the target file, and the data packets in the file buffer area whose offset sequence numbers are one greater than the offset sequence numbers of the retransmitted data packets and are continuous are written into the target file; When the retransmitted data packets arrive out of order, the step of writing the retransmitted data packets into the file buffer area is performed.
[0133] In an optional implementation, when the computer program is executed by a processor, the method of determining whether the retransmitted data packets arrive in sequence includes: Determine whether the offset sequence number of the retransmitted data packet is greater than the offset sequence number of the last received data packet by 1; When the offset sequence number of the retransmitted data packet is greater than the offset sequence number of the last received data packet by 1, it is determined that the retransmitted data packet arrives in order; When the offset sequence number of the retransmitted data packet is not greater than the offset sequence number of the last received data packet by 1, it is determined that the retransmitted data packet arrives out of order.
[0134] In an optional embodiment, when the computer program is executed by a processor, it further implements: When all data packets have not been completely received, determining whether the retransmitted data packet is the last data packet of the file; When the retransmitted data packet is the last data packet of the file, determining whether to request retransmission of all first target data packets; When retransmission of all first target data packets is not requested, retransmission of unreceived second target data packets is requested from the transmitting end device.
[0135] See also Figure 3 FIG. 2 is a schematic diagram of the structure of a communication device provided in an embodiment of the present application. In a preferred embodiment of the present application, the communication device 3 includes a memory 31 , at least one processor 32 and at least one communication bus 33 .
[0136] Those skilled in the art should understand that Figure 3The structure of the communication device shown does not constitute a limitation of the embodiments of the present application, and can be either a bus structure or a star structure. The communication device 3 can also include more or less other hardware or software than shown in the figure, or a different component arrangement.
[0137] In some embodiments, the communication device 3 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application-specific integrated circuits, programmable gate arrays, digital processors, and embedded devices. The communication device 3 may also include client devices, which include but are not limited to any electronic product that can interact with a client through a keyboard, mouse, remote control, touchpad, or voice-controlled device, such as a personal computer, tablet computer, smart phone, digital camera, etc.
[0138] It should be noted that the communication device 3 is only an example, and other existing or future electronic products that are suitable for the present application should also be included in the protection scope of the present application and included here by reference.
[0139] In some embodiments, the memory 31 stores a computer program, and when the computer program is executed by the at least one processor 32, all or part of the steps in the file transmission method as described above are implemented. The memory 31 includes a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data. Further, the computer-readable storage medium may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function, and the like.
[0140] In some embodiments, the at least one processor 32 is the control core (ControlUnit) of the communication device 3, and uses various interfaces and lines to connect the various components of the entire communication device 3, and executes various functions and processes data of the communication device 3 by running or executing the program or module stored in the memory 31, and calling the data stored in the memory 31. For example, when the at least one processor 32 executes the computer program stored in the memory, it implements all or part of the steps of the file transmission method described in the embodiment of the present application; or implements all or part of the functions of the file transmission device. The at least one processor 32 can be composed of an integrated circuit, for example, it can be composed of a single packaged integrated circuit, or it can be composed of multiple integrated circuits with the same function or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips.
[0141] In some embodiments, the at least one communication bus 33 is configured to realize the connection and communication between the memory 31 and the at least one processor 32. Although not shown, the communication device 3 may also include a power supply (such as a battery) for powering each component. Preferably, the power supply may be logically connected to the at least one processor 32 through a power management device, so as to realize the functions of managing charging, discharging, and power consumption management through the power management device. The power supply may also include any components such as one or more DC or AC power supplies, recharging power supply fault detection circuits, power converters or inverters, power status indicators, etc. The communication device 3 may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0142] The above-mentioned integrated unit implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a communication device (which can be a personal computer, a communication device, or a network device, etc.) or a processor to execute part of the method described in each embodiment of the present application.
[0143] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0144] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, and may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
Claims
1. A file transmission method, characterized in that: The method comprises: In response to receiving the file information sent by the sending end device, initializing the data packet sequence number bitmap according to the file information; Create a file buffer area and a target file for data writing; When receiving a data packet sent by the transmitting end device, updating the data packet sequence number bitmap according to the offset sequence number of the data packet; When the data packet is the last data packet received, determining the first target data packet that has not been received according to the updated data packet sequence number bitmap, and requesting the sending end device to retransmit the first target data packet; When receiving a data packet retransmitted by the sending end device, writing the retransmitted data packet into the file buffer area; When all data packets are received, the data packets in the file buffer area are written into the target file.
2. The file transmission method according to claim 1, characterized in that: Initializing the data packet sequence number bitmap according to the file information includes: Calculating the total number of data packets to be received according to the file size in the file information; Determining the offset sequence number of the data packet to be received according to the total number; Initialize a data packet sequence number bitmap according to the offset sequence number.
3. The file transmission method according to claim 1, characterized in that: Determining the first target data packet that has not been received according to the updated data packet sequence number bitmap includes: Get the target bit of the updated data packet sequence number bitmap as 0; Determine a target offset sequence number according to the target position; The data packet corresponding to the target offset sequence number is determined as the first target data packet that has not been received.
4. The file transmission method according to claim 1, characterized in that: When receiving the data packet sent by the transmitting end device, the method further includes: Check whether the receiving file has timed out; When a timeout is detected for receiving a file, relevant resources are released, and the sending device is notified of a failure in receiving the file; When no receiving file timeout is detected, whether receiving data packet timeout is detected; When a timeout of receiving a data packet is detected, it is determined whether the data packet is the last data packet received.
5. The file transmission method according to claim 4, characterized in that: The detecting whether the receiving file has timed out includes: determining whether a first time difference between the current time of the system and the time when the data packet starts to be received is greater than a preset file receiving timeout time, and when the first time difference is greater than the preset file receiving timeout time, the receiving file has timed out, and when the first time difference is not greater than the preset file receiving timeout time, the receiving file has not timed out; The detection of whether the received data packet has timed out includes: determining whether a second time difference between the current system time and the time when the data packet is received is greater than a preset data packet timeout time; when the second time difference is greater than the preset data packet timeout time, a received data packet timeout is detected; and when the second time difference is not greater than the preset data packet timeout time, a received data packet timeout is not detected.
6. The file transmission method according to claim 1, characterized in that: Before writing the retransmitted data packet into the file buffer area, the method further includes: Determining whether the retransmitted data packets arrive in order; When the retransmitted data packets arrive in order, the retransmitted data packets are directly written into the target file, and the data packets in the file buffer area whose offset sequence numbers are one greater than the offset sequence numbers of the retransmitted data packets and are continuous are written into the target file; When the retransmitted data packets arrive out of order, the step of writing the retransmitted data packets into the file buffer area is performed.
7. The file transmission method according to claim 6, characterized in that: Determining whether the retransmitted data packets arrive in order includes: Determine whether the offset sequence number of the retransmitted data packet is greater than the offset sequence number of the last received data packet by 1; When the offset sequence number of the retransmitted data packet is greater than the offset sequence number of the last received data packet by 1, it is determined that the retransmitted data packet arrives in order; When the offset sequence number of the retransmitted data packet is not greater than the offset sequence number of the last received data packet by 1, it is determined that the retransmitted data packet arrives out of order.
8. The file transmission method according to claim 1, characterized in that: The method further comprises: When all data packets have not been completely received, determining whether the retransmitted data packet is the last data packet of the file; When the retransmitted data packet is the last data packet of the file, determining whether to request retransmission of all first target data packets; When retransmission of all first target data packets is not requested, retransmission of unreceived second target data packets is requested from the transmitting end device.
9. A communication device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the file transmission method according to any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the file transmission method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
File transmission method and device, equipment and storage medium
CN111147540A
File transmission method of Flash memory, terminal and storage medium
CN111737161A
File transmission method and device, electronic equipment and readable storage medium
CN114338651A
File transmission method and device, electronic equipment and storage medium
CN116527654A
