Data transmission method and related apparatus
By adding a mark in the message header to distinguish the message boundary, the problem of high consumption of processing resources at the receiving end in the existing technology is solved, and the data processing efficiency is improved.
Patent Information
- Application Number
- PCT/CN2024/077683
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-02-22
- Filing Date
- 2024-02-20
- Publication Date
- 2024-08-29
AI Technical Summary
In network communications, the existing technology distinguishes message boundaries by searching for specific characters, which consumes high processing resources on the receiving end, resulting in low data processing efficiency.
By adding a mark to the header of the last message carrying complete data, indicating that the message is the last message among all messages carrying complete data, the receiving end only needs to check the message header to determine the message. boundary without traversing the data in the message.
It reduces the processing resource consumption of the receiving end, improves the efficiency of data processing, and reduces the performance requirements on the receiving end.
Smart Images

Figure CN2024077683_29082024_PF_FP_ABST
Abstract
Description
A data transmission method and related device
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on February 22, 2023, with application number 202310173129.1 and invention name “A Data Transmission Method and Related Devices”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of communication technology, and in particular to a data transmission method and related devices. Background Art
[0003] In the field of network communications, two communicating devices often need to construct messages according to a predefined transmission protocol and implement data communication through interactive messages.
[0004] Currently, the most widely used transmission protocol is the Transmission Control Protocol (TCP). TCP is a streaming transmission protocol. When sending data, the sender does not need to prepare all the data for a complete message before sending it; it can send parts as soon as they are prepared. The receiver needs to determine the message boundaries during the reception process and can only parse and process the message after receiving the complete message.
[0005] Therefore, to facilitate the receiver's determination of message boundaries, an application layer exists above TCP. This layer defines special characters to distinguish message boundaries. The receiver can then search for these characters in the received data to determine whether a message boundary has been reached. If a message boundary has not been reached, the receiver continues to read data from the TCP data stream. If a message boundary has been reached, the receiver parses the message.
[0006] Since searching for a specific character in data requires traversing the data, currently distinguishing message boundaries by searching for specific characters consumes a lot of processing resources on the receiving end.
[0007] Summary of the Invention
[0008] The present application provides a data transmission method that can realize message boundary determination with lower processing resources, thereby effectively improving data processing efficiency.
[0009] In a first aspect, the present application provides a data transmission method, applied to a first communication device serving as a transmitter. The method includes: a protocol stack in the first communication device obtains first data to be transmitted. The first data itself can be complete data, i.e., a segment of data with complete semantics; the first data can also be the last part of complete data, where the complete data includes multiple parts.
[0010] Next, the protocol stack in the first communication device generates at least one message based on the first data, and the at least one message is used to carry the first data. The at least one message can be one or more. When the at least one message is one, the entire first data is carried in one message. When the at least one message is multiple, each of the multiple messages carries a portion of the first data, thereby enabling multiple messages to collaboratively carry the first data.
[0011] Finally, the protocol stack of the first communication device sequentially sends at least one message, wherein the at least one message includes a first message, the first message being the last message sent among the at least one message, and the message header of the first message includes a first marker, the first marker being used to indicate that the first message is the last message among all messages used to carry the complete data. In other words, in the process of the first communication device generating and sending a message based on the last portion of data in the complete data (i.e., the first data), the first communication device may add the first marker to the last generated message (which is also the last message sent) to indicate that the message is the last message among all messages carrying the complete data, thereby facilitating the receiving end to determine the message boundary.
[0012] In this solution, the sender adds a marker to the header of the last message in at least one message carrying complete data, indicating that the message is the last of all messages corresponding to the complete data. This allows the receiver to determine message boundaries based on the marker in the message header. Since the receiver only needs to check a specific location in the header of each received message to determine whether the message carries the marker, it can determine message boundaries without having to traverse the data carried in the message. This reduces the receiver's processing resource consumption and effectively improves data processing efficiency.
[0013] In one possible implementation, the method further includes: the protocol stack in the first communication device obtains indication information, and the indication information is used to indicate that the first data is the last part of the complete data. The first data itself can be complete data, that is, there is no other partial data constituting the complete data after the first data, so the indication information can indicate that the first data is already the last part of the complete data. In addition, the complete data can also include multiple parts of data, the first data is a part of the multiple parts of data included in the complete data, and the first data is also the last part of the multiple parts of data. In general, after the first communication device completes the sending of the first data, it completes the sending of the entire complete data. In this way, after obtaining the first data, the protocol stack can add a first mark to the last message generated based on the first data (that is, the above-mentioned first message) based on the indication of the indication information to indicate that the message is the last one of all messages carrying complete data.
[0014] In this solution, by using indication information to indicate the status of the data currently acquired by the communication device, the communication device can effectively identify whether it is necessary to add a first mark to the message corresponding to the current data, thereby facilitating the subsequent receiving end to identify the message boundary.
[0015] In a possible implementation, the indication information comes from an application that generates the first data. That is, the application transmits the indication information to the protocol stack while transmitting the first data to the protocol stack.
[0016] In a possible implementation, the indication information is transmitted by the application through an extended socket interface.
[0017] For example, the application may transmit the instruction information and the first data to the protocol stack via an extended socket interface. For example, the extended socket interface may be an extended send() interface, which is used to transmit the data to be transmitted to the protocol stack and indicate whether the data to be transmitted is complete data. In addition to being able to transmit data to the protocol stack, the extended send() interface also has a newly extended function, namely, indicating whether the data currently being transmitted is the last part of the complete data.
[0018] In one possible implementation, the first marker is located in a reserved field or an extended field in the message header of the first message. The first marker may be specifically represented by a 1-bit field, and the 1-bit field may be located in a reserved field or an extended field in the message header of message 1. For example, when the value of the field used to represent the first marker is 1, it indicates that the message includes the first marker; when the value of the field used to represent the first marker is 0, it indicates that the message does not include the first marker.
[0019] In one possible implementation, at least one message is sent based on a stream transmission protocol, for example, the at least one message is sent based on TCP, that is, the first communication device does not need to wait until all messages in the at least one message are generated before executing the message sending, which can effectively ensure the data transmission efficiency.
[0020] In one possible implementation, the number of the at least one message is related to the data volume of the first data. The larger the data volume of the first data, the greater the number of the at least one message; the smaller the data volume of the first data, the smaller the number of the at least one message.
[0021] A second aspect of the present application provides a data transmission method, which is applied to a second communication device serving as a receiving end. The method includes: the second communication device sequentially receives at least one message, the at least one message including a first message, the first message being the last message received in the at least one message, and the message header of the first message including a first flag, the first flag being used to indicate that the first message is the last message among all messages used to carry complete data. The second communication device parses the at least one message to obtain first data carried in the at least one message.
[0022] In this solution, the communication device as the receiving end, during the process of receiving messages, will only trigger the parsing and processing of all previously received messages when it receives a message with the first mark in the message header. By checking the specific position in the message header of each message, the message boundary can be determined, which can effectively reduce the consumption of processing resources.
[0023] In one possible implementation, before the second communication device parses at least one message, the method further includes: the protocol stack in the second communication device caches each message in the at least one message received sequentially; after receiving the first message, the protocol stack in the second communication device returns at least one message to the application based on the first tag in the first message, and the application is used to parse the at least one message.
[0024] Specifically, the network transmission hardware (such as a network card) in the second communication device will pass each received message to the protocol stack in the second communication device. When the protocol stack in the second communication device receives each message in sequence, the protocol stack will check the message header of each message to determine whether the message header of each message has a first mark. If the protocol stack finds that the message header does not have the first mark, it is considered that the message is not the last message among all messages carrying complete data, so the message is cached; if the protocol stack finds that the message header has the first mark, it is considered that the message is the last message among all messages carrying complete data, so the message and other messages previously cached can be regarded as all messages carrying complete data.
[0025] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0026] In a possible implementation, at least one message is sent based on a stream transmission protocol.
[0027] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0028] The third aspect of the present application provides a communication device, including: an acquisition module for acquiring first data; a processing module for generating at least one message based on the first data, and the at least one message is used to carry the first data; a sending module for sending at least one message in sequence, and the at least one message includes a first message, and the first message is the last message sent among the at least one message, and the message header of the first message includes a first mark, and the first mark is used to indicate that the first message is the last message among all messages used to carry complete data.
[0029] In a possible implementation, the acquisition module is further configured to acquire indication information, where the indication information is configured to indicate that the first data is the last part of the complete data.
[0030] In a possible implementation manner, the indication information comes from an application that generates the first data.
[0031] In a possible implementation, the indication information is transmitted by the application through an extended socket interface.
[0032] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0033] In a possible implementation, at least one message is sent based on a stream transmission protocol.
[0034] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0035] The fourth aspect of the present application provides a communication device, including: a receiving module, used to receive at least one message in sequence, the at least one message includes a first message, the first message is the last message received in the at least one message, and the message header of the first message includes a first mark, the first mark is used to indicate that the first message is the last message among all messages used to carry complete data; a processing module, used to parse at least one message to obtain the first data carried in the at least one message.
[0036] In one possible implementation, the processing module is further used to: cache each message in at least one message received sequentially; after receiving a first message, return at least one message to the application based on a first tag in the first message, and the application is used to parse the at least one message.
[0037] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0038] In a possible implementation, at least one message is sent based on a stream transmission protocol.
[0039] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0040] In a fifth aspect, the present application provides a communication device, comprising: a memory and a processor; the memory stores code, and the processor is configured to execute the code. When the code is executed, the communication device executes a method as implemented in any one of the first and second aspects.
[0041] In a sixth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is run on a computer, the computer executes a method as implemented in any one of the first and second aspects.
[0042] In a seventh aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute a method as implemented in any one of the first and second aspects.
[0043] In an eighth aspect, the present application provides a chip comprising one or more processors, wherein some or all of the processors are configured to read and execute a computer program stored in a memory to perform the method in any one of the implementations of the first or second aspects.
[0044] Optionally, the chip includes a memory, and the memory is connected to the processor via a circuit or wire. Optionally, the chip also includes a communication interface, and the processor is connected to the communication interface. The communication interface is used to receive data and / or information to be processed, and the processor obtains the data and / or information from the communication interface, processes the data and / or information, and outputs the processing results through the communication interface. The communication interface can be an input / output interface. The method provided in this application can be implemented by a single chip or by multiple chips working together.
[0045] Among them, the technical effects brought about by any design method in the second to eighth aspects can refer to the technical effects brought about by different implementation methods in the above-mentioned first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] FIG1 is a system architecture diagram in related art;
[0047] FIG2 is a schematic diagram of a data transmission process based on TCP in the related art;
[0048] FIG3 is a schematic structural diagram of a communication device 101 provided in an embodiment of the present application;
[0049] FIG4 is a flow chart of a data transmission method provided in an embodiment of the present application;
[0050] FIG5 is a schematic diagram of a message format provided in an embodiment of the present application;
[0051] FIG6 is a schematic diagram of another message format provided in an embodiment of the present application;
[0052] FIG7 is a schematic diagram of an architecture used in a data transmission method provided in an embodiment of the present application;
[0053] FIG8 is a schematic diagram of a data transmission process according to an embodiment of the present application;
[0054] FIG9 is a schematic diagram of a data receiving process according to an embodiment of the present application;
[0055] FIG10 is a schematic structural diagram of a communication device provided in an embodiment of the present application;
[0056] FIG11 is a schematic structural diagram of another communication device provided in an embodiment of the present application;
[0057] FIG12 is a schematic diagram of the structure of an execution device provided in an embodiment of the present application;
[0058] FIG13 is a schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments.
[0060] The terms "first," "second," "third," "fourth," and the like (if any) in the specification and claims of this application and in the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or sequential sequence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having," and any variations thereof, are intended to cover non-exclusive inclusions, e.g., a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0061] To facilitate understanding, some technical terms involved in the embodiments of this application are first introduced below.
[0062] (1) Open System Interconnection Reference Model (OSI model)
[0063] The OSI model is a conceptual model proposed by the International Organization for Standardization. It's essentially a standard framework designed to interconnect various computers worldwide. The OSI divides computer network architecture into seven layers: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, and application layer. The functions of these seven layers are as follows.
[0064] Physical layer: Converts data into electronic signals that can be transmitted through physical media, equivalent to the porters in the post office.
[0065] Data Link Layer: Determines how the network medium is accessed. Data is typically framed and flow control is handled at the Data Link Layer. The Data Link Layer specifies the topology and provides hardware addressing, similar to the post office's box loader.
[0066] Network layer: Routes data through large networks, acting like a sorting worker in a post office.
[0067] Transport layer: provides reliable end-to-end connections, equivalent to the postman in the company.
[0068] Session layer: allows users to establish connections using simple and easy-to-remember names, which is equivalent to a secretary in a company who receives and sends letters, writes envelopes, and opens envelopes.
[0069] Presentation layer: negotiates data exchange formats, equivalent to the assistant who briefs the boss and writes letters for the boss in the company.
[0070] Application layer: The interface between the user's application and the network.
[0071] (2) TCP
[0072] TCP is a connection-oriented, reliable, byte-stream-based transport layer communication protocol. Specifically, TCP is a transmission protocol designed to provide reliable end-to-end byte streams over unreliable internet networks.
[0073] (3) User Datagram Protocol (UDP)
[0074] UDP is a connectionless transport layer protocol in the OSI model, providing simple, transaction-oriented, unreliable information delivery services. Like TCP, UDP handles data packets. In the OSI model, both reside in the transport layer, above the network layer. UDP has the disadvantage of not providing packet grouping, reassembly, or sequencing. This means that once a message is sent, it is impossible to determine whether it has arrived safely and intact. UDP is used to support network applications that require data transmission between computers. Many client / server network applications, including online video conferencing systems, rely on UDP. Currently, many applications, such as multimedia data streams, exclusively support UDP, generating no additional data and refusing to retransmit known corrupted packets. UDP is the best choice when transmission performance is prioritized over integrity, such as in audio and multimedia applications. UDP is also a good choice when data transmission is so short that the preceding connection process constitutes the bulk of the traffic.
[0075] (4) Stream Control Transmission Protocol (SCTP)
[0076] SCT is a protocol for transmitting multiple data streams simultaneously between the two ends of a network connection.
[0077] (5) Hypertext Transfer Protocol (HTTP)
[0078] HTTP is a simple request-response protocol that typically runs on top of TCP. It specifies what messages a client may send to a server and what responses it may receive.
[0079] (6) Message
[0080] A message is a unit of data exchanged and transmitted on a network, a block of data that a station wants to send at one time. A message contains the complete data information to be sent, and its length is highly variable and unrestricted.
[0081] Generally speaking, a message usually consists of a message header and a payload. The message header is some additional information segments encapsulated to achieve data transmission; the payload is used to carry the actual data to be transmitted.
[0082] (7) Message Header
[0083] The message header is usually also referred to as the message header. It refers to some information segments encapsulated in the head of the message to indicate some information required for the message during transmission.
[0084] (8) Socket
[0085] A socket is an abstraction for bidirectional communication endpoints between application processes on different hosts on a network. A socket is one end point for communication between processes on a network, providing a mechanism for application-layer processes to exchange data using network protocols. In terms of its position, a socket connects the application process above and the network protocol stack below. It is the interface through which applications communicate using network protocols and the interface between applications and the network protocol stack.
[0086] (9) News
[0087] The message described in this embodiment refers to a data unit for information exchange between processes or software components. A message is a piece of data with complete semantics, such as a complete HTTP request, a complete HTTP response, a complete video frame, or a complete Remote Procedure Call (RPC) request. A message is different from a packet. A packet is a data unit exchanged and transmitted in a network, that is, a block of data that a site wants to send at one time. A packet is only a unit of transmission and has no semantic requirements, while a message is a data unit with complete semantics. A longer message needs to be carried by multiple packets, while a short message may be less than the length of a packet.
[0088] (10) Message transmission
[0089] Message transmission means that the sender first determines whether the currently prepared data is a complete message when transmitting data. If the currently prepared data is not a complete message, it continues to wait for data until all data is ready before sending data to the receiver.
[0090] (11) Streaming
[0091] In streaming, the concept of a stream is like the flow of water, without boundaries. Streaming refers to an unbounded stream of bytes. For example, during data transmission, the sender first sends a 100-byte segment, followed by a 200-byte segment. During the streaming process, these data merge into an unbounded stream, eliminating the 100-byte and 200-byte boundaries. On the receiving end, the data receiver can retrieve any length of data from the streaming channel in a single operation (or wait if there is no data in the channel). The data receiver is unaware of the data boundaries. In the above example, the receiver can receive 50 bytes in the first operation and then attempt to receive 300 bytes in the next operation. At this point, there are only 250 bytes in the streaming channel. Software implementations can allow the receiver to wait for the remaining 50 bytes or return the existing 250 bytes.
[0092] (12) Reliable transmission
[0093] Reliable transmission means that the transmission protocol itself guarantees the reliability of data transmission. Specifically, after sending data, the sender confirms that the data was correctly received by the receiver. Specific measures include: 1. After receiving data, the receiver sends an acknowledgment message to the sender. Upon receiving the acknowledgment message, the sender assumes that the data was correctly received. For example, in a phone call between A and B, A tells B, "I have a meeting this afternoon." B confirms, "Got it, I'll meet this afternoon." Upon receiving the acknowledgment message, A assumes that B has correctly received the message "meeting this afternoon." If A does not receive B's acknowledgment, it will repeat the message "meeting this afternoon." If it still does not receive B's acknowledgment after repeated attempts, the call is considered unsuccessful. The acknowledgment mechanism implicitly includes a data retransmission mechanism, meaning that if the sender does not receive an acknowledgment message, it will retransmit the data. 2. The sender and receiver have mechanisms to control the data transmission rate. If the sender sends data too quickly, the receiver or intermediate network nodes (such as switches and routers that forward data) cannot process the data, resulting in data loss. The sender and / or receiver must have a mechanism to detect data loss or excessive load (including excessive load on the sender itself or on intermediate nodes) and reduce the sending rate when data loss or excessive load occurs. For example, in the above scenario of a phone call between A and B, if A speaks too fast, B can respond by saying "Please speak slower."
[0094] (13) Unreliable transmission
[0095] Unreliable transmission refers to data transmission without guaranteeing that the receiving end will receive the data. Typically, the sender is solely responsible for sending the data, without requesting feedback from the receiving end or controlling the transmission rate. For example, a television station sending a television signal is an example of unreliable transmission; it simply tries to send the signal regardless of whether the receiving end receives it.
[0096] (14) Protocol stack
[0097] A protocol stack, also known as a protocol stack, is a specific software implementation of a computer network protocol suite. A protocol in a protocol suite is typically designed for a single purpose, which simplifies design. Because each protocol module typically communicates with two other protocol modules above and below it, they can often be thought of as layers in a protocol stack. The lowest-level protocol always describes the physical interaction with the hardware. Each higher-level layer adds more features. User applications only process the top-level protocol.
[0098] (15) Maximum Transmission Unit (MTU)
[0099] MTU generally refers to the maximum length of a message, typically expressed in bytes. It is used to inform the other party of the maximum size of a data unit that can be accepted, indicating the payload size that the sender can accept. Specifically, Ethernet has a limit on message length, and its MTU is generally 1500 bytes. Most message lengths of different types of networks have an upper limit. If a communication device has a data packet to transmit, and the packet length is larger than the MTU, the communication device needs to perform fragmentation, that is, to divide the data packet into pieces so that each piece of data is no larger than the MTU.
[0100] Currently, there are two common semantics for data transmission over networks: message transmission and stream transmission. Based on whether data can be reliably delivered, transmission is further categorized as reliable or unreliable. Table 1 shows the classification of transmission types based on these two dimensions.
[0101] Table 1
[0102] Currently, most applications on the Internet use TCP for data transmission. A few applications that do not require high reliability but have high real-time requirements (such as audio and video conferencing) use UDP for data transmission, while SCTP is rarely used in practice.
[0103] Most applications use reliable streaming transport (TCP) because, on the one hand, applications require error-free data transmission, that is, reliable transmission. On the other hand, streaming transport has the following advantages over message transmission: Streaming transport makes it easier to design efficient flow control algorithms and achieve high throughput; Message transmission usually has a limit on the size of a single message, while streaming transport has no such limit and can continuously transmit data of any size for a long time.
[0104] In reality, although most applications use reliable streaming, semantically, the data transmitted is often segmented into messages with specific semantics. For example, the data transmitted by HTTP in a TCP stream consists of individual HTTP requests or responses, each of which is a message with complete semantics. HTTP requests and responses can be further divided into a header and a body. There is a boundary between the header and the body, and the header and body both have complete semantics.
[0105] So, within a TCP stream, how does HTTP distinguish request boundaries and the boundaries between headers and bodies? The answer is that HTTP uses special characters and length fields within the protocol to distinguish boundaries. HTTP assumes that received data begins with a header, and until it finds the string "\r\n\r\n," it considers the following data to be the body. The length of the body is indicated within the header via the Content-Length field. Understandably, searching for a specific string in the data requires traversing the data, which is very expensive. Therefore, distinguishing the boundaries between headers and bodies, as well as between multiple requests, is very costly for the receiving device.
[0106] In general, most current applications use TCP for reliable streaming. However, they require message semantics, meaning they segment data into messages for interpretation and processing. Therefore, they typically set their own boundaries within the data. Distinguishing message boundaries within the data stream is expensive for applications, requiring operations such as searching for special strings and parsing length fields.
[0107] For example, see Figure 1, which illustrates a system architecture in related art. As shown in Figure 1, applications use TCP at the transport layer. TCP streams data without distinguishing message boundaries. Above TCP lies the application layer, which distinguishes message boundaries by defining special characters or adding a length field.
[0108] Please refer to Figure 2, which is a schematic diagram of the TCP-based data transmission process in the related art. As shown in Figure 2, when sending data, the sender only needs to prepare part of the data to be sent before sending the data. It does not need to prepare all the data of a complete message before sending. In other words, it can send part of the data as soon as it is ready.
[0109] When receiving data, the application first reads data from the TCP data stream. Because TCP is a streaming transmission, this portion of data may not be a complete message and lacks complete semantics. The application then searches the data for boundary characters or calculates the message length to determine whether a message boundary has been reached. For example, when data transmission is based on the HTTP protocol, the application searches the data for the string "\r\n\r\n" to determine whether the end of the HTTP header has been reached. If the application determines that the message boundary has not been reached by searching the data for the string, it continues reading data from the TCP stream. If the application determines that the message boundary has been reached by searching the data for the string, it parses the message. However, the application needs to traverse the data to search for the string, which consumes a lot of processing resources and results in a high performance cost in distinguishing message boundaries.
[0110] It should be noted that, since the data in the TCP data stream is carried by messages, the application searches for character strings in the data carried in the payload field of the message.
[0111] In view of this, an embodiment of the present application provides a data transmission method, which makes minor changes on the basis of the existing stream transmission protocol. Specifically, the sending end adds a mark to the message header of the last message in at least one message carrying complete data to indicate that the message is the last message among all messages corresponding to the completed data, so that the receiving end can determine the message boundary based on the mark in the message header. Since the receiving end only needs to check the specific position in the message header of each received message to determine whether the message carries the mark, the message boundary can be determined without traversing the large amount of data carried in the message. Therefore, the processing resource consumption of the receiving end is low, which can effectively improve the efficiency of data processing.
[0112] The data transmission method provided in the embodiments of the present application can be applied to a communication device. For example, the communication device can be a server, a mobile phone, a personal computer (PC), a laptop, a tablet computer, a smart TV, a mobile internet device (MID), a wearable device, a virtual reality (VR) device, an augmented reality (AR) device, a wireless communication device in industrial control, a wireless communication device in self-driving, a wireless communication device in remote medical surgery, a wireless communication device in a smart grid, a wireless communication device in transportation safety, a wireless communication device in a smart city, a wireless communication device in a smart home, etc.
[0113] Please refer to Figure 3, which is a schematic diagram of the structure of a communication device 101 provided in an embodiment of the present application. As shown in Figure 3, the communication device 101 includes a processor 103, which is coupled to a system bus 105. The processor 103 can be one or more processors, each of which can include one or more processor cores. A display adapter (video adapter) 107 can drive a display 109, which is coupled to the system bus 105. The system bus 105 is coupled to an input / output (I / O) bus via a bus bridge 111. An I / O interface 115 is coupled to the I / O bus. The I / O interface 115 communicates with various I / O devices, such as an input device 117 (e.g., a touch screen), an external memory 121 (e.g., a hard disk, floppy disk, optical disk, or USB flash drive), a multimedia interface, etc., a transceiver 123 (capable of sending and / or receiving radio communication signals), a camera 155 (capable of capturing still and dynamic digital video images), and an external USB port 125. Optionally, the interface connected to the I / O interface 115 may be a USB interface.
[0114] The processor 103 may be any conventional processor, including a reduced instruction set computing (RISC) processor, a complex instruction set computing (CISC) processor, or a combination thereof. Alternatively, the processor may be a dedicated device such as an ASIC.
[0115] Communication device 101 can communicate with software deployment server 149 via network interface 129. Exemplarily, network interface 129 is a hardware network interface, such as a network card. Network 127 can be an external network, such as the Internet, or an internal network, such as Ethernet or a virtual private network (VPN). Alternatively, network 127 can be a wireless network, such as a WiFi network or a cellular network.
[0116] The hard drive interface 131 is coupled to the system bus 105. The hard drive interface is connected to the hard drive 133. The internal memory 135 is coupled to the system bus 105. The data running in the internal memory 135 may include the operating system (OS) 137 of the communication device 101, the application program 143, and the scheduler.
[0117] The operating system consists of a shell 139 and a kernel 141. Shell 139 is an interface between the user and the operating system's kernel. The shell is the outermost layer of the operating system. The shell manages the interaction between the user and the operating system: it waits for user input, interprets user input to the operating system, and processes various operating system output.
[0118] The kernel 141 consists of the parts of the operating system that manage memory, files, peripherals, and system resources. The kernel 141 directly interacts with the hardware. The operating system kernel typically runs processes and provides inter-process communication, CPU time slice management, interrupts, memory management, and I / O management.
[0119] For example, when the communication device 101 is a smart phone, the application 143 includes an instant messaging-related program. In one embodiment, when the application 143 needs to be executed, the communication device 101 can download the application 143 from the software deployment server 149 .
[0120] Please refer to Figure 4, which is a flow chart of a data transmission method provided in an embodiment of the present application. As shown in Figure 4, the data transmission method includes the following steps 401-406.
[0121] Step 401: A first communication device obtains first data to be transmitted.
[0122] In this embodiment, the first communication device is a transmitting end, configured to transmit data to the second communication device as a receiving end.
[0123] The first data to be transmitted may be generated by an application in the first communication device, such as a browser or social media application in the first communication device. After the application generates the first data, it may pass the first data to the software responsible for data transmission (e.g., a protocol stack), so that the protocol stack can implement data transmission based on the corresponding transmission protocol. Therefore, after the application passes the first data to the protocol stack, the first communication device can obtain the first data to be transmitted.
[0124] Specifically, the first data itself can be complete data, that is, a piece of data with complete semantics, such as a complete HTTP request, a complete HTTP response, a complete video frame, or a complete RPC request.
[0125] In addition, the first data may also be the last part of the complete data, which includes multiple parts of data, that is, the first communication device successively obtains multiple parts of data, and the first data is the last part of the complete data.
[0126] Step 402: The first communication device generates at least one message according to the first data, where the at least one message is used to carry the first data.
[0127] In this embodiment, at least one message may refer to one or more messages, that is, the first communication device may generate one message or multiple messages according to the first data.
[0128] The number of at least one message generated by the first communication device based on the first data is related to the data volume of the first data. It is understandable that, because messages have a maximum length limit, when the length of the first data exceeds the maximum message length (i.e., when the data volume of the first data is too large), the first communication device cannot carry the first data in a single message, but instead needs to divide the first data into multiple data slices, and carry each data slice separately in multiple messages.
[0129] Therefore, when the data amount of the first data is less than or equal to the maximum data amount that a message can carry, the first communication device generates a message based on the first data; when the data amount of the first data is greater than the maximum data amount that a message can carry, the first communication device generates multiple messages based on the first data.
[0130] When the first communication device generates a message based on the first data, the protocol stack in the first communication device may encapsulate a message header based on the first data based on a transmission protocol for transmitting the first data, thereby obtaining a message carrying the first data.
[0131] When the first communication device generates multiple messages based on the first data, the protocol stack in the first communication device may divide the first data into multiple data slices and encapsulate a message header based on each data slice based on the transmission protocol, thereby obtaining multiple messages. Each of the multiple messages carries a portion of the first data, so the multiple messages can carry the first data.
[0132] Optionally, when the protocol stack in the first communication device obtains the first data from the application, the protocol stack may also obtain indication information from the application, where the indication information is used to indicate that the first data is the last part of the complete data. The first data itself may be complete data, that is, there is no other partial data constituting the complete data after the first data, so the indication information may indicate that the first data is already the last part of the complete data. In addition, the complete data may also include multiple parts of data, the first data is a part of the multiple parts of data included in the complete data, and the first data is also the last part of the multiple parts of data. In general, after the first communication device completes the sending of the first data, it completes the sending of the entire complete data.
[0133] In this way, after obtaining the first data, the protocol stack can add a first mark to the last message generated based on the first data (ie, the first message mentioned above) to indicate that the message is the last one of all messages carrying complete data.
[0134] Exemplarily, the application may transmit the indication information and the first data to the protocol stack via an extended socket interface. For example, the extended socket interface may be an extended send() interface, which is used to transmit the data to be transmitted to the protocol stack and indicate whether the data to be transmitted is complete data. In addition to being able to transmit data to the protocol stack, the extended send() interface also has a newly extended function, namely, indicating whether the data currently being transmitted is the last part of the complete data.
[0135] Furthermore, if the application program passes data to the protocol stack by calling the extended send() interface and the protocol stack receives the aforementioned indication information, the protocol stack may deem the currently received data to be complete and add the first marker to the last message generated based on the data. If the application program passes data to the protocol stack by calling the extended send() interface and the protocol stack does not receive the aforementioned indication information, the protocol stack may deem the currently received data to be incomplete and not add the first marker to any messages generated based on the data.
[0136] In step 403, the first communication device sends at least one message to the second communication device in sequence, wherein the at least one message includes a first message, the first message is the last message sent, and the message header of the first message includes a first mark, and the first mark is used to indicate that the first message is the last message among all messages used to carry complete data.
[0137] During the process of the first communication device generating at least one message based on the first data, the first communication device may send the generated message to the second communication device each time it generates a message, until all of the at least one generated message are sent in sequence. In other words, the at least one message generated by the first communication device is sent based on a stream transmission protocol (e.g., TCP), i.e., the first communication device does not need to wait until all of the messages in the at least one message are completely generated before sending the message.
[0138] For example, if a first communication device divides first data into data slice 1, data slice 2, and data slice 3, and encapsulates data slice 1, data slice 2, and data slice 3 to obtain messages 1, 2, and 3, respectively, the first communication device first encapsulates data slice 1 to obtain message 1. The first communication device can then send the encapsulated message 1 to the second communication device; at the same time, the first communication device can continue to encapsulate data slice 2 to obtain message 2. That is, the sending of message 1 and the encapsulation of message 2 are performed simultaneously; the first communication device does not need to wait until all messages 1, 2, and 3 are encapsulated before sending all messages.
[0139] During the process of encapsulating and sending multiple messages by the first communication device, the first communication device sequentially encapsulates the messages based on the data slices divided by the first data. Therefore, after the first communication device sequentially encapsulates each message, it also sequentially sends each encapsulated message. In this way, when the first communication device sends the last message of the at least one message to the second communication device, it means that all messages carrying the complete first data have been sent to the second communication device. Therefore, when the first communication device encapsulates the last message of the at least one message (i.e., the first message), the first communication device can add a first mark to the first message to indicate that the first message is the last message of all messages used to carry the complete data.
[0140] In the case where the first communication device only generates one message based on the first data (that is, the at least one message mentioned above only includes one message), the message generated by the first communication device already carries complete data, that is, this message is the first message mentioned above, and therefore the first message includes the first tag.
[0141] In general, in the process of a first communication device generating and sending a message based on the last part of the data in the complete data (i.e., the first data), the first communication device can add a first mark in the last generated message (which is also the last message sent) to indicate that the message is the last message among all messages carrying the complete data, so as to facilitate the receiving end to determine the boundary of the message.
[0142] The first marker can be understood as a message end marker, indicating that the message carrying the first marker is the last message of a message. Therefore, receiving the message carrying the first marker means that a complete message has been received, that is, complete data has been received.
[0143] Optionally, the first marker is located in a reserved field or an extension field in the message header of the first message. The first marker may be specifically represented by a 1-bit field, and the 1-bit field may be located in a reserved field or an extension field in the message header of message 1. For example, when the value of the field used to represent the first marker is 1, it indicates that the message includes the first marker; when the value of the field used to represent the first marker is 0, it indicates that the message does not include the first marker.
[0144] For example, please refer to Figure 5, which is a schematic diagram of the format of a message provided in an embodiment of the present application. As shown in Figure 5, a message generally includes a payload and multiple message headers, and the multiple message headers specifically include a transport layer header (corresponding to the TCP / UDP protocol), a network layer header (corresponding to the IP protocol), and a data link layer header. The multiple message headers may include reserved fields or extended fields, so the first mark can be set in the reserved fields or extended fields of any message header.
[0145] As shown in Figure 5, the transport layer header can be, for example, a TCP header. The fields in the TCP header specifically include: source port, destination port, sequence number, acknowledgment sequence number, header length, reserved field, window size, checksum, urgent pointer, and options. Among them, the reserved field is a field reserved in advance and has no actual transmission significance. Therefore, the first marker can be set in the reserved field of the TCP header. In addition, in addition to the fields in the transport layer header, the first marker can also be set in the data link layer header or the network layer header. This embodiment does not specifically limit this.
[0146] In addition, please refer to Figure 6, which is a schematic diagram of another message format provided in an embodiment of the present application. As shown in Figure 6, in some cases, the message may also include a private protocol header, that is, a header obtained based on a transmission protocol published by a non-standard organization. In this case, the first tag can also be set in a reserved field or an extension field of the private protocol header.
[0147] Step 404: The second communication device receives at least one message in sequence.
[0148] Because the first communication device sequentially sends at least one message generated by it to the second communication device, the second communication device also sequentially receives at least one message from the first communication device. The message header of the last received first message among the at least one message includes a first flag, and the first flag is used to indicate that the first message is the last message among all messages used to carry complete data.
[0149] Step 405: The second communication device buffers each message of the at least one message received sequentially.
[0150] In this embodiment, when the second communication device sequentially receives each message in at least one message, the second communication device caches each received message so as to parse and process one or more messages belonging to the same message after determining the message boundary.
[0151] Specifically, the network transmission hardware (such as a network card) in the second communication device will pass each received message to the protocol stack in the second communication device. When the protocol stack in the second communication device receives each message in sequence, the protocol stack will check the message header of each message to determine whether the message header of each message has a first mark. If the protocol stack finds that the message header does not have the first mark, it is considered that the message is not the last message among all messages carrying complete data, so the message is cached; if the protocol stack finds that the message header has the first mark, it is considered that the message is the last message among all messages carrying complete data, so the message and other messages previously cached can be regarded as all messages carrying complete data.
[0152] It is understood that, if the first data itself is complete data, the at least one message generated based on the first data is all messages carrying the complete data. If the first data is only a portion of the complete data, the at least one message generated based on the first data is only a portion of all messages carrying the complete data, and the second communication device can regard the first message and other messages buffered before the first message that do not have the first tag as all messages carrying the complete data.
[0153] Step 406: The second communication device parses at least one message to obtain first data carried in the at least one message.
[0154] After the second communication device has sequentially received at least one message, based on the first tag in the last received first message among the at least one message, the second communication device can determine that the first message is the last message carrying complete data. Therefore, the second communication device can determine that the first message and other messages cached before the first message (e.g., the at least one message described above) are all messages carrying complete data. Therefore, the second communication device can trigger parsing of the at least one message based on the first tag in the first message, thereby obtaining the first data carried in the at least one message.
[0155] It should be noted that if the first data itself is complete data, the second communication device can obtain the complete data by parsing the at least one message mentioned above. If the first data is only a portion of the complete data, since the first data is the last part of the complete data, the second communication device will not only receive the at least one message carrying the first data, but also other messages carrying the remaining portions of the complete data. The second communication device can obtain the complete data by parsing the at least one message and the other messages carrying the remaining portions of the complete data.
[0156] Specifically, after the protocol stack in the second communication device receives the first message, the protocol stack may determine, based on the first marker in the first message, that the first message is the last message. Therefore, the protocol stack may return other cached messages and the first message (i.e., the at least one message described above) to the application program to facilitate parsing of the at least one message by the application program. The protocol stack may return the entire at least one message to the application program, or it may strip off the message header from the at least one message and then return the first data carried in the at least one message to the application program. This embodiment does not specifically limit this.
[0157] The above introduces a data transmission method provided by an embodiment of the present application. The specific execution process of the data transmission method will be described in detail below with reference to specific examples.
[0158] For example, please refer to Figure 7, which is a schematic diagram of the architecture used in a data transmission method provided in an embodiment of the present application. As shown in Figure 7, the first communication device and the second communication device have the same software architecture, namely, the first communication device and the second communication device include an application, a protocol stack, and a protocol stack interface, and deploy a reliable stream transmission protocol. The software architecture within the first communication device and the second communication device is described below.
[0159] The first communication device and the second communication device are devices that participate in data interaction, for example, they can be terminal devices such as smart phones, personal computers, laptops, etc., and can also be network devices such as switches and routers.
[0160] Application: A computer program that performs one or more specific tasks on the first and second communication devices. The applications on the first and second communication devices need to exchange data with each other. For example, the applications on the first and second communication devices are both social media applications that need to exchange data entered by the user through the social media application.
[0161] Protocol stack: A program in an operating system used to send and receive network messages, such as the protocol stack in the Linux kernel.
[0162] Protocol stack interface: The interface provided by the kernel protocol stack to the upper layer (e.g., the application layer where the application resides), namely, the standard socket interface. Common interfaces include the send() interface, recv() interface, socket() interface, bind() interface, listen() interface, accept() interface, connect() interface, close() interface, etc. Among them, the send() interface is used to send data, and the recv() interface is used to receive data. In this embodiment, new parameter values are added to the send() interface and recv() interface to support the sending and receiving of message semantics.
[0163] Reliable stream transmission protocol: This embodiment provides a transmission protocol. The reliable stream transmission protocol is not a completely redesigned new message transmission protocol, but a mature stream transmission protocol (such as TCP) with minor modifications to support message semantics.
[0164] Message: In this embodiment, a message end mark is added to the message, indicating that the message is the last message of a message. Receiving the message indicates that a complete message has been received.
[0165] The following describes in detail the protocol stack interface and reliable stream transmission protocol that have been extended and modified in this embodiment.
[0166] Regarding the protocol stack interface, in this embodiment, the send() interface and the recv() interface are extended.
[0167] The current send() interface is: ssize_t send(int sockfd,const void*buf,size_t len,int flags).
[0168] ssize_t send(int sockfd,const void*buf,size_t len,int flags) is a C language function named send, which defines four parameters. Specifically, int sockfd,const void*buf,size_t len, and int flags represent the types of the parameters. The current values of the int flags parameter include MSG_CONFIRM, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOR, MSG_MORE, MSG_NOSIGNAL, and MSG_OOB.
[0169] In this embodiment, a new value, MSG_FINISHED, is added to the int flags parameter. This value indicates that the data to be sent is the end of a message, that is, the last part of the complete data. In other words, the MSG_FINISHED parameter in the int flags parameter of the send() interface is equivalent to the indication information described in the above embodiment, indicating that the data transmitted by the current send() interface is the last part of the complete data.
[0170] Each value MSG_XXX in the parameter int flags is a bit (similar to 1, 2, 4, 8, and other powers of 2, representing a bit in a 32-bit integer). Therefore, in actual extended applications, you only need to define MSG_FINISHED to be different from the existing parameter int flags value.
[0171] For example, assuming that the length of a complete data is 4000 bytes, the application can send the complete data by calling the send() interface four times. Specifically, the manner in which the application calls the send() interface four times can be as follows.
[0172] send(fd,buf,1000,0); / / Send 1000 bytes without setting the flag
[0173] send(fd,buf,1000,0); / / send another 1000 bytes without setting the flag
[0174] send(fd,buf,1000,0); / / send another 1000 bytes without setting the flag
[0175] send(fd,buf,1000,MSG_FINISHED); / / Send the last 1000 bytes and set the message end mark
[0176] That is to say, the application can pass data to the protocol stack by calling the send() interface multiple times. When the application calls the send() interface to pass a part of the complete data to the protocol stack, and this part of the data is not the last part of the data, the application can not set the MSG_FINISHED value in the parameter int flags, thereby instructing the protocol stack not to set the message end mark when sending the message corresponding to this part of the data. When the application calls the send() interface to pass the last part of the complete data to the protocol stack, the application can set the MSG_FINISHED value in the parameter int flags, thereby instructing the protocol stack to set the message end mark when sending the message corresponding to this part of the data.
[0177] In this way, the application does not need to prepare complete data before passing it to the protocol stack. Instead, it can prepare partial data and pass it to the protocol stack, thereby ensuring the timeliness of data transmission and avoiding data transmission congestion. Moreover, when passing the last part of data, the application sets the MSG_FINISHED value to indicate that the data currently being passed is the last part of data, which enables the protocol stack to set a message end mark when sending the message corresponding to this part of data, so that the receiving communication device can quickly and effectively determine the message boundary.
[0178] The current recv() interface is: ssize_t recv(int sockfd,void*buf,size_t len,int flags).
[0179] The recv() interface is a pair with the send() interface. The send() interface is used to send data, and the recv() interface is used to receive data.
[0180] In this embodiment, a new value is added to the parameter int flags in the recv() interface: MSG_FULL, which means that the program returns only after receiving a complete message.
[0181] Corresponding to the above example of sending a message, the specific method of calling the recv() interface to receive a message can be:
[0182] recv(fd,buf,5000,MSG_FULL); / / Receive a complete data at one time
[0183] Unlike traditional message receiving interfaces, the recv() interface in this embodiment provides full flexibility. When an application calls the recv() interface, it can set the MSG_FULL parameter to instruct the protocol stack to return only after receiving a complete set of data. If the MSG_FULL parameter is set, the protocol stack will return data to the application only after receiving a complete set of data (i.e., the last message carrying complete data). The returned data is complete data.
[0184] The application can also call the recv() interface without setting the MSG_FULL parameter. If the MSG_FULL parameter is not set, the performance of the recv() interface is the same as that of the normal stream transmission recv() interface, that is, the protocol stack returns the data to the application as long as it receives it, regardless of whether the data is complete.
[0185] The following describes the differences between the reliable stream transmission protocol provided by this embodiment and the reliable stream transmission protocol in related technologies.
[0186] Difference 1: When the sending application passes data to the protocol stack through the send() interface and sets the MSG_FINISHED flag, the protocol stack sends this part of the data and sets the message end flag for the last message of this part of the data.
[0187] For example, if an application calls send(fd, buf, 3000, MSG_FINISHED) and the current network MTU is 1000, meaning a message can carry a maximum of 1000 bytes of data, this send() call will trigger the generation of three messages. This means the protocol stack will encapsulate this data into three messages, but will only set the message end marker in the last message.
[0188] Difference 2: When the receiving application calls the recv() interface to receive data and the MSG_FULL flag is set, the protocol stack returns data to the application only after receiving a complete data set. If the MSG_FULL flag is not set, the protocol stack returns data to the application immediately upon receiving the data.
[0189] For example, if the sending application calls send(fd,buf,3000,MSG_FINISHED) to send a 3000-byte message, if the receiving application calls recv(fd,buf,3000,0) without setting the MSG_FULL flag, the protocol stack will block the receiving thread at the recv() call when it does not receive any data; if the protocol stack receives the first 1000-byte message, it will let recv() return, and the returned content contains 1000 bytes of data, but it is not a complete data.
[0190] If the sending application calls send(fd,buf,3000,MSG_FINISHED) to send a 3000-byte message, and the receiving end calls recv(fd,buf,3000,MSG_FULL), the protocol stack will block the receiving thread at the recv() call when it does not receive any data. When the protocol stack receives the first 1000-byte message, it will check the message and find no message end marker, so it will cache the message. It will not return the complete 3000-byte data to the recv() call until it receives the third message and finds the message reception marker.
[0191] The following will describe the detailed process of sending data by a communication device as a sending end and receiving data by a communication device as a receiving end in an embodiment of the present application through specific examples.
[0192] For example, please refer to Figure 8, which is a schematic diagram of a data transmission process provided by an embodiment of the present application. As shown in Figure 8, when a first communication device as a transmitter sends data to a second communication device as a receiver, the following steps 801-809 are executed.
[0193] Step 801: An application of a first communication device prepares HTTP header data, where the HTTP header data is complete data.
[0194] Specifically, when an application of a first communication device needs to send an HTTP message to an application of a second communication device, the application of the first communication device often prepares HTTP header data first to send the HTTP header message to the application of the second communication device.
[0195] In step 802 , the application of the first communication device calls the socket interface to transmit HTTP header data to the protocol stack, and indicates that the HTTP header data is complete data.
[0196] After preparing the HTTP header data, the application of the first communication device may call a socket interface (such as the send() interface mentioned above) to transmit the HTTP header data to the protocol stack and indicate that the HTTP header data is complete data.
[0197] For example, the send() interface function called by the application of the first communication device may specifically be: send(fd, buf, size, MSG_FINISHED), that is, MSG_FINISHED is used to indicate that the data of the currently transmitted HTTP header is complete data.
[0198] Step 803: The protocol stack of the first communication device generates at least one message based on the data of the HTTP header, and sends the at least one message to the second communication device, wherein the last message in the at least one message is set with a message end marker.
[0199] Specifically, the number of messages generated by the protocol stack based on the HTTP header data is related to the amount of data in the HTTP header. The larger the amount of data in the HTTP header data, the more messages the protocol stack generates; the smaller the amount of data in the HTTP header data, the fewer messages the protocol stack generates.
[0200] In addition, since the application indicates that the data in the HTTP header is complete data when passing it to the protocol stack, the protocol stack adds a message end marker to the last message of at least one generated message to indicate that the message is the last one of all messages carrying complete data.
[0201] Step 804 : The application of the first communication device continues to prepare partial data of the HTTP body.
[0202] After the application completes preparation and passes the HTTP header data to the protocol stack, it continues to prepare the HTTP body data. Furthermore, because the HTTP body data is complex and often requires concatenating the output data of multiple modules, the application currently prepares part of the HTTP body data first.
[0203] In step 805 , the application of the first communication device calls the socket interface to transmit partial data of the HTTP body to the protocol stack, and indicates that the partial data of the HTTP body is not complete data.
[0204] After the application prepares partial data of the HTTP body, it can call the socket interface to pass the partial data of the HTTP body to the protocol stack, and at the same time indicate through the socket interface that the partial data of the HTTP body is not complete data.
[0205] For example, the send() interface function called by the application of the first communication device may be specifically: send(fd, buf, size, 0), that is, not setting the MSG_FINISHED flag to indicate that the data of the currently transmitted HTTP body is not complete data.
[0206] Step 806: The protocol stack of the first communication device generates at least one message based on part of the HTTP header data, and sends the at least one message to the second communication device. All messages in the at least one message are not set with a message end marker.
[0207] Because the application indicates that the partial data of the HTTP body is not complete data when passing it to the protocol stack, the protocol stack does not add a message end marker in all the messages generated to indicate that these messages are not the last of all messages carrying complete data.
[0208] Step 807 : The application of the first communication device continues to prepare the remaining data of the HTTP body.
[0209] In step 808 , the application of the first communication device calls the socket interface to transmit the remaining data of the HTTP body to the protocol stack, and indicates that the remaining data of the HTTP body is the last part of the complete data.
[0210] After the application prepares the remaining data of the HTTP body, it can continue to call the socket interface to pass the remaining data of the HTTP body to the protocol stack, and at the same time indicate through the socket interface that the partial data of the HTTP body is the last part of the complete data.
[0211] For example, the send() interface function called by the application of the first communication device may specifically be: send(fd, buf, size, MSG_FINISHED), that is, MSG_FINISHED is used to indicate that the data of the HTTP body currently being transmitted is complete data.
[0212] Step 809: The protocol stack of the first communication device generates at least one message based on the remaining data of the HTTP header, and sends the at least one message to the second communication device, wherein the last message in the at least one message is set with a message end marker.
[0213] Because the application indicates that the remaining data of the HTTP body is the last part of the complete data when passing it to the protocol stack, the protocol stack adds a message end marker to the last message of at least one generated message to indicate that the message is the last one of all messages carrying complete data.
[0214] For example, please refer to Figure 9, which is a schematic diagram of a data reception process provided by an embodiment of the present application. As shown in Figure 9, when the second communication device at the receiving end receives data sent by the first communication device as the sending end, it executes the following steps 901-906.
[0215] In step 901, the application of the second communication device calls the socket interface to receive data and indicates that it wishes to receive a complete set of data.
[0216] In this step, the application can call the recv() interface to receive data from the protocol stack, and the application can indicate to the protocol stack that it wants to receive a complete set of data through the parameter value of the recv() interface.
[0217] For example, the recv() interface function called by the application may specifically be: recv(fd, buf, len, MSG_FULL), where the MSG_FULL parameter value is used to indicate that a complete data set is desired to be received.
[0218] Step 902: The protocol stack sequentially receives messages sent by the first communication device.
[0219] In the process of the first communication device sending messages to the second communication device in sequence, the protocol stack in the second communication device will receive the messages sent by the first communication device in sequence.
[0220] Step 903: The protocol stack checks whether a message end marker is set in the message header of the received message.
[0221] Step 904: If the message end marker is not set in the message header of the message received by the protocol stack, the received message is buffered and subsequent messages are continued to be received.
[0222] If the message end marker is not set in the message header of the message received by the protocol stack, it means that the message received by the protocol stack is not the last one of all messages carrying complete data. Therefore, the protocol stack caches the received message and continues to receive subsequent messages.
[0223] Step 905: If a message end marker is set in the message header of the message received by the protocol stack, all cached messages are parsed and processed, and data obtained by parsing the messages is returned to the application.
[0224] If the message header of the message received by the protocol stack contains a message end marker, it means that the protocol stack has received the last of all messages carrying complete data. Therefore, the protocol stack can parse and process all cached messages (that is, all messages carrying complete data) and return the data obtained by parsing the messages to the application.
[0225] Step 906: The application processes the received data.
[0226] The above embodiments introduce the data transmission method provided by the embodiments of the present application. The following will introduce the device that executes the above data transmission method.
[0227] Please refer to Figure 10, which is a schematic diagram of the structure of a communication device provided in an embodiment of the present application. As shown in Figure 10, the communication device includes: an acquisition module 1001, configured to acquire first data; a processing module 1002, configured to generate at least one message based on the first data, the at least one message being configured to carry the first data; and a sending module 1003, configured to sequentially send at least one message, the at least one message including a first message, the first message being the last message sent among the at least one message, and the message header of the first message including a first marker, the first marker being configured to indicate that the first message is the last message among all messages configured to carry the complete data.
[0228] In a possible implementation, the acquisition module 1001 is further configured to acquire indication information, where the indication information is configured to indicate that the first data is the last part of the complete data.
[0229] In a possible implementation manner, the indication information comes from an application that generates the first data.
[0230] In a possible implementation, the indication information is transmitted by the application through an extended socket interface.
[0231] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0232] In a possible implementation, at least one message is sent based on a stream transmission protocol.
[0233] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0234] Please refer to Figure 11, which is a schematic diagram of the structure of another communication device provided in an embodiment of the present application. As shown in Figure 11, the communication device includes: a receiving module 1101, configured to sequentially receive at least one message, wherein the at least one message includes a first message, the first message being the last message received in the at least one message, and the message header of the first message including a first marker, the first marker being configured to indicate that the first message is the last message among all messages used to carry complete data; and a processing module 1102, configured to parse the at least one message to obtain the first data carried in the at least one message.
[0235] In one possible implementation, the processing module 1102 is further used to: cache each message in at least one message received sequentially; after receiving a first message, return at least one message to the application based on a first tag in the first message, and the application is used to parse the at least one message.
[0236] In a possible implementation manner, the first tag is located in a reserved field or an extended field in a message header of the first message.
[0237] In a possible implementation, at least one message is sent based on a stream transmission protocol.
[0238] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0239] Next, an execution device provided in an embodiment of the present application is introduced. Please refer to Figure 12. Figure 12 is a structural schematic diagram of an execution device provided in an embodiment of the present application. The execution device 1200 can be specifically manifested as a mobile phone, a tablet, a laptop computer, a smart wearable device, a server, etc., which is not limited here. Specifically, the execution device 1200 includes: a receiver 1201, a transmitter 1202, a processor 1203 and a memory 1204 (wherein the number of processors 1203 in the execution device 1200 can be one or more, and Figure 12 takes one processor as an example), wherein the processor 1203 may include an application processor 12031 and a communication processor 12032. In some embodiments of the present application, the receiver 1201, the transmitter 1202, the processor 1203 and the memory 1204 may be connected via a bus or other means.
[0240] The memory 1204 may include a read-only memory and a random access memory, and provides instructions and data to the processor 1203. A portion of the memory 1204 may also include non-volatile random access memory (NVRAM). The memory 1204 stores processor and operation instructions, executable modules, or data structures, or subsets or extended sets thereof. The operation instructions may include various operation instructions for implementing various operations.
[0241] Processor 1203 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together via a bus system. In addition to a data bus, the bus system may also include a power bus, a control bus, and a status signal bus. However, for clarity, all bus systems are referred to as a bus system in the figure.
[0242] The methods disclosed in the above embodiments of the present application can be applied to or implemented by processor 1203. Processor 1203 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits or software instructions in processor 1203. The above processor 1203 can be a general-purpose processor, a digital signal processor (DSP), a microprocessor, or a microcontroller, and can further include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The processor 1203 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in conjunction with the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in memory 1204, and processor 1203 reads the information in memory 1204 and, in conjunction with its hardware, completes the steps of the above method.
[0243] Receiver 1201 can be used to receive input digital or character information and generate signal input related to executing device-related settings and function control. Transmitter 1202 can be used to output digital or character information through the first interface. Transmitter 1202 can also be used to send instructions to the disk pack through the first interface to modify data in the disk pack. Transmitter 1202 can also include a display device such as a display screen.
[0244] In an embodiment of the present application, in one case, the processor 1203 is used to execute the method in the embodiment corresponding to Figure 4.
[0245] The electronic device provided in the embodiment of the present application may specifically be a chip, and the chip includes: a processing unit and a communication unit, the processing unit may be, for example, a processor, and the communication unit may be, for example, an input / output interface, a pin or a circuit, etc. The processing unit may execute the computer execution instructions stored in the storage unit so that the chip in the execution device executes the rendering method described in the above embodiment. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit may also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.
[0246] Please refer to Figure 13, which is a schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present application. The present application also provides a computer-readable storage medium. In some embodiments, the method disclosed in Figure 4 above can be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or on other non-transitory media or products.
[0247] 13 schematically illustrates a conceptual partial view of an example computer-readable storage medium including a computer program for executing a computer process on a computing device, arranged in accordance with at least some embodiments presented herein.
[0248] In one embodiment, computer-readable storage medium 1300 is provided using signal-bearing medium 1301. Signal-bearing medium 1301 may include one or more program instructions 1302 that, when executed by one or more processors, may provide the functionality or portions of the functionality described above with respect to FIG. 4. Furthermore, program instructions 1302 in FIG. 13 also depict example instructions.
[0249] In some examples, the signal bearing medium 1301 may include a computer readable medium 1303 such as, but not limited to, a hard drive, a compact disk (CD), a digital video disk (DVD), a digital tape, a memory, a ROM or RAM, and the like.
[0250] In some embodiments, the signal-bearing medium 1301 may include a computer-recordable medium 1304, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, or the like. In some embodiments, the signal-bearing medium 1301 may include a communication medium 1305, such as, but not limited to, a digital and / or analog communication medium (e.g., a fiber optic cable, a waveguide, a wired communication link, a wireless communication link, or the like). Thus, for example, the signal-bearing medium 1301 may be communicated via a wireless form of the communication medium 1305 (e.g., a wireless communication medium conforming to the IEEE 802 standard or other transmission protocol).
[0251] The one or more program instructions 1302 may be, for example, computer-executable instructions or logic-implemented instructions. In some examples, the computing device may be configured to provide various operations, functions, or actions in response to the program instructions 1302 communicated to the computing device via one or more of computer-readable media 1303, computer-recordable media 1304, and / or communication media 1305.
[0252] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0253] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrations. Available media can be magnetic media (e.g., floppy disk, hard disk, tape), optical media (e.g., DVD), or semiconductor media (e.g., solid-state drive (SSD)).
[0254] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0255] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0256] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0257] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0258] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0259] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A data transmission method, characterized in that: include: Acquire first data; Generate at least one message according to the first data, where the at least one message is used to carry the first data; The at least one message is sent sequentially, wherein the at least one message includes a first message, the first message is the last message sent among the at least one message, and the message header of the first message includes a first mark, and the first mark is used to indicate that the first message is the last message among all messages used to carry complete data.
2. The method according to claim 1, characterized in that The method further comprises: Obtain indication information, where the indication information is used to indicate that the first data is the last part of complete data.
3. The method according to claim 2, characterized in that The indication information comes from an application that generates the first data.
4. The method according to claim 3, characterized in that The indication information is transmitted by the application through an extended socket interface.
5. The method according to any one of claims 1 to 4, characterized in that: The first tag is located in a reserved field or an extended field in a message header of the first message.
6. The method according to any one of claims 1 to 5, characterized in that: The at least one message is sent based on a stream transmission protocol.
7. The method according to any one of claims 1 to 6, characterized in that: The number of the at least one message is related to the data volume of the first data.
8. A data transmission method, characterized in that: include: receiving at least one message in sequence, wherein the at least one message includes a first message, the first message is the last message received among the at least one message, and a message header of the first message includes a first mark, and the first mark is used to indicate that the first message is the last message among all messages used to carry complete data; Parse the at least one message to obtain first data carried in the at least one message.
9. The method according to claim 8, characterized in that Before parsing the at least one message, the method further includes: Buffering each message of the at least one message received sequentially; After receiving the first message, the at least one message is returned to the application based on the first tag in the first message, and the application is used to parse the at least one message.
10. The method according to claim 8 or 9, characterized in that: The first tag is located in a reserved field or an extended field in a message header of the first message.
11. The method according to any one of claims 8 to 10, characterized in that: The at least one message is sent based on a stream transmission protocol.
12. The method according to any one of claims 8 to 11, characterized in that: The number of the at least one message is related to the data volume of the first data.
13. A communication device, characterized in that: include: An acquisition module, used for acquiring first data; a processing module, configured to generate at least one message according to the first data, wherein the at least one message is used to carry the first data; A sending module is used to send the at least one message in sequence, wherein the at least one message includes a first message, the first message is the last message sent among the at least one message, and the message header of the first message includes a first mark, and the first mark is used to indicate that the first message is the last message among all messages used to carry complete data.
14. The device according to claim 13, characterized in that The acquisition module is further used to acquire indication information, where the indication information is used to indicate that the first data is the last part of the complete data.
15. The device according to claim 14, characterized in that The indication information comes from an application that generates the first data.
16. The device according to claim 14, characterized in that The indication information is transmitted by the application through an extended socket interface.
17. The device according to any one of claims 13 to 16, characterized in that: The first tag is located in a reserved field or an extended field in a message header of the first message.
18. A communication device, characterized in that: include: A receiving module, used to sequentially receive at least one message, wherein the at least one message includes a first message, the first message is the last message received in the at least one message, and a message header of the first message includes a first mark, and the first mark is used to indicate that the first message is the last message among all messages used to carry complete data; The processing module is used to parse the at least one message to obtain the first data carried in the at least one message.
19. The device according to claim 18, characterized in that The processing module is further used for: Buffering each message of the at least one message received sequentially; After receiving the first message, the at least one message is returned to the application based on the first tag in the first message, and the application is used to parse the at least one message.
20. The device according to claim 18 or 19, characterized in that The first tag is located in a reserved field or an extended field in a message header of the first message.
21. A communication device, characterized in that: The device comprises a memory and a processor; the memory stores codes, the processor is configured to execute the codes, and when the codes are executed, the device executes the method according to any one of claims 1 to 12.
22. A computer storage medium, characterized in that The computer storage medium stores instructions, which, when executed by a computer, cause the computer to implement the method of any one of claims 1 to 12.
23. A computer program product, characterized in that The computer program product stores instructions, which, when executed by a computer, cause the computer to implement the method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Protocol frame transmission method, device, node apparatus and system
CN107078837A
Data transmission method and device
CN108111523A
Data transmission method and device
CN114531212A
Data transmission method and device, electronic equipment and readable storage medium
CN114844842A
Last sequence number indication
US20210329551A1
