Data transmission method and related device
By adding tags to the TCP message header, the problem of high resource consumption at the receiving end in determining message boundaries is solved and more efficient data processing is achieved.
Patent Information
- Application Number
- CN202310173129.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-22
- Publication Date
- 2024-08-23
AI Technical Summary
In network communications, the processing resources required by the receiving end to determine message boundaries are high. Especially when using the TCP protocol, the performance cost is high due to the need to traverse the data to search for specific characters to distinguish message boundaries.
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 data processing efficiency, and reduces the time and calculation cost of determining message boundaries.
Smart Images

Figure CN118540392A
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a data transmission method and related devices. Background Art
[0002] 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.
[0003] At present, the widely used transmission protocol is the Transmission Control Protocol (TCP). TCP is a stream transmission protocol. When sending data, the sender does not need to prepare all the data of a complete message before sending it. It can send part of it as soon as it is prepared; the receiver needs to determine the boundaries of the message during the receiving process and can only parse and process it after receiving the complete message.
[0004] Therefore, in order to facilitate the receiver to determine the message boundary, there is an application layer above TCP, which can distinguish the message boundary by defining special characters. In this way, the receiver can search for boundary characters in the received data to determine whether the message boundary has been reached. If the message boundary has not been reached, the receiver continues to read data from the TCP data stream; if the message boundary has been reached, the receiver parses the message.
[0005] 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. Summary of the invention
[0006] The present application provides a data transmission method, which can realize message boundary determination with lower processing resources and effectively improve the efficiency of data processing.
[0007] The first aspect of the present application provides a data transmission method, which is applied to a first communication device 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, that is, a piece of data with complete semantics; the first data can also be the last part of the complete data, and the complete data includes multiple parts of data.
[0008] Secondly, the protocol stack in the first communication device generates at least one message according to the first data, and the at least one message is used to carry the first data. The number of the at least one message can be one or more. When the number of the at least one message is one, the entire first data is carried in one message; when the number of the at least one message is multiple, each of the multiple messages carries a part of the first data, thereby realizing that multiple messages collaboratively carry the first data.
[0009] Finally, the protocol stack of the first communication device sequentially sends at least one message, 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, the first mark is used to indicate that the first message is the last message among all messages used to carry complete data. That is to say, in the process of the 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 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 complete data, so as to facilitate the receiving end to determine the boundary of the message.
[0010] In this solution, 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 in all messages corresponding to the complete 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 a specific position in the message header of each received message to determine whether the message carries a mark, the message boundary can be determined without traversing the data carried in the message, so the processing resource consumption of the receiving end is low, which can effectively improve the efficiency of data processing.
[0011] In a 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. Among them, 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 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 transmission of the first data, the transmission of the entire complete data is completed. In this way, after the protocol stack obtains the first data, it can add a first mark in 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.
[0012] 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.
[0013] 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.
[0014] In a possible implementation, the indication information is transmitted by the application through an extended socket interface.
[0015] For example, the application may transmit the indication information and the first data to the protocol stack through 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 new extended function, namely, indicating whether the data currently being transmitted is the last part of the complete data.
[0016] In a possible implementation, the first tag is located in a reserved field or an extended field in a message header of the first message. The first tag 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 a message header of message 1. For example, when the value of the field used to represent the first tag is 1, it indicates that the message includes the first tag; when the value of the field used to represent the first tag is 0, it indicates that the message does not include the first tag.
[0017] 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 for all messages in the at least one message to be generated before executing message sending, which can effectively ensure data transmission efficiency.
[0018] In a 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.
[0019] The second aspect of the present application provides a data transmission method, which is applied to a second communication device as a receiving end. The method includes: the second communication device receives 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. The second communication device parses at least one message to obtain the first data carried in the at least one message.
[0020] In this scheme, when the communication device as the receiving end is receiving messages, it 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.
[0021] In one possible implementation, before the second communication device parses at least one message, the method also includes: the protocol stack in the second communication device caches each message of at least one message received in sequence; 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.
[0022] 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 of 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 of all messages carrying complete data, so the message and other messages previously cached can be regarded as all messages carrying complete data.
[0023] 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.
[0024] In a possible implementation manner, at least one message is sent based on a stream transmission protocol.
[0025] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0026] The third aspect of the present application provides a communication device, including: an acquisition module, used to acquire first data; a processing module, used to generate 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, used to send at least one message in sequence, 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.
[0027] In a possible implementation, 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.
[0028] In a possible implementation manner, the indication information comes from an application that generates the first data.
[0029] In a possible implementation, the indication information is transmitted by the application through an extended socket interface.
[0030] 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.
[0031] In a possible implementation manner, at least one message is sent based on a stream transmission protocol.
[0032] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0033] 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, and 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.
[0034] In one possible implementation, the processing module is also used to: cache each message in at least one message received sequentially; after receiving a first message, return at least one message to an application based on a first tag in the first message, and the application is used to parse at least one message.
[0035] 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.
[0036] In a possible implementation manner, at least one message is sent based on a stream transmission protocol.
[0037] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0038] In a fifth aspect, the present application provides a communication device, comprising: a memory and a processor; the memory stores codes, and the processor is configured to execute the codes. When the codes are executed, the communication device executes a method as implemented in any one of the first aspect or the second aspect.
[0039] A sixth aspect of 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 or second aspects.
[0040] A seventh aspect of 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 or second aspects.
[0041] In an eighth aspect, the present application provides a chip, comprising one or more processors, wherein some or all of the processors are used to read and execute a computer program stored in a memory to execute the method in any one of the implementations of the first or second aspect.
[0042] Optionally, the chip includes a memory, and the memory is connected to the processor through 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 and output interface. The method provided in the present application can be implemented by one chip, or by multiple chips in collaboration.
[0043] 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
[0044] Figure 1 A system architecture diagram in the related technology;
[0045] Figure 2 It is a schematic diagram of data transmission process based on TCP in related technology;
[0046] Figure 3 A schematic diagram of the structure of a communication device 101 provided in an embodiment of the present application;
[0047] Figure 4A flowchart of a data transmission method provided in an embodiment of the present application;
[0048] Figure 5 A schematic diagram of a message format provided in an embodiment of the present application;
[0049] Figure 6 A schematic diagram of another message format provided in an embodiment of the present application;
[0050] Figure 7 A schematic diagram of an architecture used in a data transmission method provided in an embodiment of the present application;
[0051] Figure 8 A schematic diagram of a data transmission process provided in an embodiment of the present application;
[0052] Fig. 9 A schematic diagram of a data receiving process provided in an embodiment of the present application;
[0053] Fig.10 A schematic diagram of the structure of a communication device provided in an embodiment of the present application;
[0054] Fig.11 A schematic diagram of the structure of another communication device provided in an embodiment of the present application;
[0055] Fig.12 A schematic diagram of the structure of an execution device provided in an embodiment of the present application;
[0056] Fig.13 A schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION
[0057] 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 of the embodiments.
[0058] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be 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, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0059] To facilitate understanding, some technical terms involved in the embodiments of the present application are first introduced below.
[0060] (1) Open System Interconnection Reference Model (OSI Model)
[0061] The OSI model is a conceptual model proposed by the International Organization for Standardization. It is actually a standard framework that attempts to interconnect various computers into a network worldwide. OSI divides the computer network architecture into the following seven layers: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, and application layer. The functions of the seven-layer structure are as follows.
[0062] Physical layer: Converts data into electronic signals that can be transmitted through physical media, equivalent to the porters in the post office.
[0063] Data Link Layer: Determines how the network medium is accessed. Data is usually framed and flow control is handled at the Data Link Layer. The Data Link Layer specifies the topology and provides hardware addressing, which is equivalent to the box loader in the post office.
[0064] Network layer: Routes data through large networks, the equivalent of sorting workers in a post office.
[0065] Transport layer: provides reliable end-to-end connections, equivalent to the postman in a company.
[0066] 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.
[0067] Presentation layer: negotiates the data exchange format, equivalent to the assistant who briefs the boss and writes letters for the boss in a company.
[0068] Application layer: The interface between the user's application and the network.
[0069] (2) TCP
[0070] 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 on unreliable Internet networks.
[0071] (3) User Datagram Protocol (UDP)
[0072] UDP is a connectionless transport layer protocol in the OSI model, providing a simple, transaction-oriented, unreliable information transmission service. UDP is used to process data packets like TCP. In the OSI model, both are located in the transport layer, one layer above the network layer. UDP has the disadvantages of not providing packet grouping, assembly, and inability to sort data packets. That is to say, after a message is sent, it is impossible to know whether it has arrived safely and completely. UDP is used to support network applications that need to transmit data between computers. Many client / server network applications, including network video conferencing systems, need to use the UDP protocol. At present, many applications only support UDP, such as multimedia data streams, do not generate any additional data, and do not resend packets even if they are known to be damaged. When the emphasis is on transmission performance rather than transmission integrity, such as audio and multimedia applications, UDP is the best choice. UDP is also a good choice when the data transmission time is so short that the previous connection process becomes the main body of the entire traffic.
[0073] (4) Stream Control Transmission Protocol (SCTP)
[0074] SCT is a protocol for transmitting multiple data streams simultaneously between two ends of a network connection.
[0075] (5) Hyper Text Transfer Protocol (HTTP)
[0076] HTTP is a simple request-response protocol that usually runs on top of TCP. It specifies what messages a client may send to a server and what responses it may get.
[0077] (6) Message
[0078] A message is a unit of data exchanged and transmitted in a network, that is, a block of data to be sent by a station at one time. A message contains the complete data information to be sent, and its length is very inconsistent, unlimited and variable.
[0079] 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 data that actually needs to be transmitted.
[0080] (7) Message Header
[0081] The message header is usually referred to as the message header for short. It refers to some information segments encapsulated in the head of the message to indicate some information required for the message during transmission.
[0082] (8) Socket
[0083] Socket is an abstraction of the endpoint for two-way communication between application processes on different hosts in the network. A socket is one end of the process communication on the network, providing a mechanism for application layer processes to exchange data using network protocols. In terms of its position, the socket is connected to the application process at the top and the network protocol stack at the bottom. It is the interface for the application to communicate through the network protocol and the interface for the application to interact with the network protocol stack.
[0084] (9) Message
[0085] 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 message. A message is a data unit exchanged and transmitted in a network, that is, a block of data to be sent by a site at one time. A message is only a unit of transmission and has no requirements for semantics, while a message is a data unit with complete semantics. A longer message needs to be carried by multiple messages, while a short message may be less than the length of a message.
[0086] (10) Message transmission
[0087] 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 are ready before sending data to the receiver.
[0088] (11) Streaming
[0089] For stream transmission, the concept of stream is similar to water flow, which has no boundaries. Stream transmission refers to a byte stream without boundaries. For example, during data transmission, the sender first sends a segment of 100 bytes of data, and then sends a segment of 200 bytes of data. During the process of stream transmission, these data converge into a stream without boundaries, and the above-mentioned 100-byte and 200-byte boundaries no longer exist. At the receiving end, the data receiver can take out data of any length from the stream transmission channel in one operation (if there is no data in the channel, it can wait), and the data receiver cannot perceive the boundaries of the data. In the above example, the receiver can receive 50 bytes in the first operation, and the next operation can try to receive 300 bytes. At this time, there are only 250 bytes in the stream transmission channel. In terms of software implementation, the receiver can wait for the remaining 50 bytes, or return the existing 250 bytes first.
[0090] (12) Reliable transmission
[0091] Reliable transmission means that the transmission protocol itself guarantees the reliability of data transmission. Specifically, after the sender sends data, it will confirm that the data is correctly received by the receiver. The specific measures include: 1. After receiving the data, the receiver will send a confirmation message to the sender. When the sender receives the confirmation message, it believes that the data is correctly received by the receiver. For example, A and B are talking on the phone. A says to B "I have a meeting this afternoon." B confirms that "I received it and requested a meeting this afternoon." When A receives the confirmation message, it believes that B has correctly received the message "Meeting this afternoon." If A does not receive B's confirmation, it will repeatedly send "Meeting this afternoon" to B. If it has not received B's confirmation after repeated attempts, it is considered that the call has failed. The confirmation mechanism implies a data retransmission mechanism, that is, if the sender does not receive the confirmation message, it will retransmit. 2. The sender and the receiver have a mechanism to control the data transmission rate. If the data transmission rate of the sender is too fast, the receiver or the intermediate nodes in the network (switches and routers that forward data, etc.) cannot handle it, which will cause data loss. The sender and / or receiver must have a mechanism to sense data loss or excessive load (including excessive load on itself or excessive load on intermediate nodes), and reduce the sending rate when data is lost or the load is too large. For example, in the above scenario of A and B talking on the phone, if A speaks too fast, B can give feedback by saying "Please speak slower."
[0092] (13) Unreliable transmission
[0093] Unreliable transmission means that when data is sent, there is no guarantee that the receiving end will receive the data. The usual practice is that the sender is only responsible for sending the data, does not require feedback from the receiving end, and does not control the sending rate. For example, a TV station sending a TV signal is an unreliable transmission. It just tries its best to send the signal, regardless of whether the receiving end receives it.
[0094] (14) Protocol stack
[0095] 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 usually designed for only one purpose, which makes design easier. Because each protocol module usually communicates with two other protocol modules above and below, they can usually be imagined as layers in a protocol stack. The lowest level protocol always describes the physical interaction with the hardware. Each higher level adds more features. User applications only deal with the top-level protocol.
[0096] (15) Maximum Transmission Unit (MTU)
[0097] MTU usually refers to the maximum length of a message, usually in bytes, and is used to inform the other party of the maximum size of the data unit that can be accepted, indicating the size of the payload that the sender can accept. Specifically, Ethernet has a limit on the length of messages, 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 length of the data packet is larger than the MTU, then the communication device needs to perform fragmentation, that is, divide the data packet into pieces so that each piece of data is no larger than the MTU.
[0098] At present, when using the network for data transmission, there are two common semantics: message transmission and stream transmission. In terms of whether the data can be reliably delivered, it is further divided into reliable transmission and unreliable transmission. The results of classifying transmission types according to these two dimensions can be shown in Table 1.
[0099]
[0100] 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.
[0101] The reason why most applications use reliable stream transmission (TCP) is, on the one hand, because the applications require that the transmitted data cannot be error-free, that is, reliable transmission; on the other hand, stream transmission has the following advantages over message transmission: stream transmission is easier to design efficient flow control algorithms and easier to achieve high throughput; message transmission usually has a limit on the size of a single message, but stream transmission has no such limit and can continuously transmit data of any size for a long time.
[0102] In reality, although most applications use reliable stream transmission, in terms of semantics, the transmitted data is more likely to be messages with certain semantics. For example, the data transmitted by HTTP in the TCP stream is one HTTP request or one HTTP response, and each HTTP request or HTTP response is a message with complete semantics. HTTP requests and HTTP responses can be divided into headers and bodies. There is a boundary between headers and bodies, and headers have complete semantics, and bodies also have complete semantics.
[0103] So in the TCP stream, how does HTTP distinguish the boundaries of requests 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 believes that the received data starts with a header, and until it finds the string "\r\n\r\n", it believes that the following data is the body. The length of the body part is described in the header through a Content-Length field. It is understandable that searching for a specific string in the data requires traversing the data, and the search cost is very high, so the receiving device spends a lot of money to distinguish the boundaries between headers and bodies and the boundaries between multiple requests.
[0104] In general, most applications currently use TCP for reliable streaming, but they require message semantics, that is, segmenting data into messages for interpretation and processing, so they usually set boundaries in the data themselves. It is costly for applications to distinguish message boundaries in the data stream, such as searching for special strings, parsing length fields, etc.
[0105] For example, see Figure 1 , Figure 1 It is a system architecture diagram in the related technology. Figure 1 As shown in the figure, the application uses TCP at the transport layer. TCP performs stream transmission and does not distinguish message boundaries. There is an application layer above TCP. The application layer distinguishes message boundaries by defining special characters or adding length fields.
[0106] See also Figure 2 , Figure 2 FIG. 1 is a schematic diagram of a data transmission process based on TCP in the related art. Figure 2 As shown, when the sender sends data, it only needs to prepare part of the data to be sent before sending the data. It is not necessary to prepare all the data of a complete message before sending, that is, it can send part of the data as soon as part of it is prepared.
[0107] When the receiving end is receiving data, the application first reads the data from the TCP data stream. Since TCP is a stream transmission, the data read out may not be a complete message and does not have complete semantics. Then, the application searches for boundary characters in the data or calculates the message length to determine whether the message boundary has been reached. For example, when the data transmission is based on the HTTP protocol, the application will search for the "\r\n\r\n" string in the data 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 string in the data, it continues to read data from the TCP stream; if the application determines that the message boundary has been reached by searching the string in the data, the message is parsed. Among them, the application needs to traverse the data when searching for the string in the data, so it needs to consume more processing resources, resulting in a high performance cost for distinguishing message boundaries.
[0108] It should be noted that, since the data in the TCP data stream is carried by messages, the application searches for the character string in the data carried in the payload field of the message.
[0109] 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.
[0110] The data transmission method provided in the embodiment of the present application can be applied to a communication device. Exemplarily, the communication device can be, for example, 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.
[0111] See also Figure 3 , Figure 3 1 is a schematic diagram of the structure of a communication device 101 provided in an embodiment of the present application. Figure 3 As shown, the communication device 101 includes a processor 103, and the processor 103 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, the display adapter can drive a display 109, and the display 109 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 a variety of I / O devices, such as an input device 117 (such as a touch screen, etc.), an external memory 121 (for example, a hard disk, a floppy disk, an optical disk or a USB flash drive), a multimedia interface, etc.). A transceiver 123 (which can send and / or receive radio communication signals), a camera 155 (which can capture static and dynamic digital video images) and an external USB port 125. Optionally, the interface connected to the I / O interface 115 can be a USB interface.
[0112] 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.
[0113] The communication device 101 can communicate with the software deployment server 149 through the network interface 129. Exemplarily, the network interface 129 is a hardware network interface, such as a network card. The network 127 can be an external network, such as the Internet, or an internal network, such as Ethernet or a virtual private network (VPN). Optionally, the network 127 can also be a wireless network, such as a WiFi network, a cellular network, etc.
[0114] The hard disk drive interface 131 is coupled to the system bus 105. The hard disk drive interface is connected to the hard disk drive 133. The internal memory 135 is coupled to the system bus 105. The data running in the internal memory 135 may include an operating system (OS) 137 of the communication device 101, an application program 143, and a scheduler.
[0115] The operating system includes a shell 139 and a kernel 141. Shell 139 is an interface between the user and the kernel of the operating system. The shell is the outermost layer of the operating system. The shell manages the interaction between the user and the operating system: waiting for user input, interpreting user input to the operating system, and processing various operating system output results.
[0116] The kernel 141 consists of those parts of the operating system that manage memory, files, peripherals, and system resources. The kernel 141 interacts directly with the hardware. The operating system kernel usually runs processes and provides communication between processes, provides CPU time slice management, interrupts, memory management, IO management, etc.
[0117] Exemplarily, 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 .
[0118] See also Figure 4 , Figure 4 A flow chart of a data transmission method provided in an embodiment of the present application. Figure 4As shown, the data transmission method includes the following steps 401-406.
[0119] Step 401: A first communication device obtains first data to be transmitted.
[0120] In this embodiment, the first communication device is a transmitting end, which is used to transmit data to the second communication device as a receiving end.
[0121] The first data to be transmitted may be generated by an application in the first communication device, for example, by an application such as a browser or social software in the first communication device. After the application generates the first data, the application may pass the first data to the software (such as a protocol stack) responsible for data transmission, so that the protocol stack can realize 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.
[0122] Specifically, the first data itself may 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.
[0123] In addition, the first data may also be the last part of the complete data, and the complete data 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 data constituting the complete data.
[0124] Step 402: The first communication device generates at least one message according to the first data, and the at least one message is used to carry the first data.
[0125] 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.
[0126] The number of at least one message generated by the first communication device according to the first data is related to the data volume of the first data. It is understandable that, since the message has a maximum length limit, when the length of the first data is greater than the maximum length of the message (that is, when the data volume of the first data is too large), the first communication device cannot carry the first data through one message, but needs to divide the first data into multiple data slices, and use multiple messages to carry each data slice respectively.
[0127] 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.
[0128] 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.
[0129] In the case where the first communication device generates multiple messages based on the first data, the protocol stack in the first communication device may be to 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 message in the multiple messages carries a part of the first data, so the multiple messages can realize the carrying of the first data.
[0130] 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, and 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 are 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, the sending of the entire complete data is completed.
[0131] In this way, after acquiring 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.
[0132] Exemplarily, the application may transmit the indication information and the first data to the protocol stack through 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 new extended function, namely, indicating whether the data currently being transmitted is the last part of the complete data.
[0133] In addition, if the application transfers data to the protocol stack by calling the extended send() interface, and the protocol stack obtains the above indication information, the protocol stack can consider the currently obtained data as complete data, and then add the first mark to the last message generated based on the data. If the application transfers data to the protocol stack by calling the extended send() interface, and the protocol stack does not obtain the above indication information, the protocol stack can consider the currently obtained data as incomplete data, and then do not add the first mark to all messages generated based on the data.
[0134] 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.
[0135] In the process of the first communication device generating at least one message according to the first data, each time the first communication device generates a message, the generated message can be sent to the second communication device until all the generated at least one message is 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 (such as TCP), that is, the first communication device does not need to wait until all messages in the at least one message are fully generated before sending the message.
[0136] For example, when the first communication device divides the first data into data slice 1, data slice 2 and data slice 3, and encapsulates the first data into message 1, message 2 and message 3 based on data slice 1, data slice 2 and data slice 3 respectively, the first communication device first encapsulates the message 1 based on data slice 1. Then, the first communication device can send the encapsulated message 1 to the second communication device; at the same time, the first communication device can continue to encapsulate the message 2 based on data slice 2. That is, the sending of message 1 and the encapsulation of message 2 are carried out at the same time, and the first communication device does not need to wait until all messages 1, message 2 and message 3 are encapsulated before executing the sending of all messages.
[0137] In the process of encapsulating and sending multiple messages by the first communication device, the first communication device encapsulates the messages in sequence based on the data slices divided by the first data. Therefore, after the first communication device encapsulates each message in sequence, it also sends the encapsulated messages in sequence. 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 in the first message to indicate that the first message is the last message of all messages used to carry the complete data.
[0138] In the case where the first communication device only generates one message based on the first data (ie, the at least one message mentioned above includes only 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.
[0139] In general, in the process of a first communication device generating and sending a message based on the last part of 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.
[0140] The first mark can be understood as a message end mark, indicating that the message carrying the first mark is the last message of a message. Therefore, receiving the message carrying the first mark means that a complete message has been received, that is, complete data has been received.
[0141] Optionally, the first tag is located in a reserved field or an extended field in a message header of the first message. The first tag 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 a message header of message 1. For example, when the value of the field used to represent the first tag is 1, it indicates that the message includes the first tag; when the value of the field used to represent the first tag is 0, it indicates that the message does not include the first tag.
[0142] For example, see Figure 5 , Figure 5 A schematic diagram of a message format provided in an embodiment of the present application. Figure 5As shown, 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. In the multiple message headers, a reserved field or an extended field may be included, so the first mark can be set in the reserved field or the extended field of any one of the message headers.
[0143] like Figure 5 As shown, the transport layer header may be, for example, a TCP header, and the fields in the TCP header specifically include: source port, destination port, sequence number, confirmation 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 substantial transmission significance, so the first mark may be set in the reserved field of the TCP header. In addition, in addition to the fields in the transport layer header, the first mark may also be set in the data link layer header or the network layer header, which is not specifically limited in this embodiment.
[0144] Also, see Figure 6 , Figure 6 A schematic diagram of another message format provided in an embodiment of the present application. Figure 6 As shown, in some cases, the message may also have a private protocol header, that is, a header obtained based on a transmission protocol issued by a non-standard organization. In this case, the first mark may also be set in a reserved field or an extended field of the private protocol header.
[0145] Step 404: The second communication device receives at least one message in sequence.
[0146] Since 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. Among the at least one message, the message header of the last received 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.
[0147] Step 405: The second communication device buffers each message of at least one message received sequentially.
[0148] In this embodiment, when the second communication device receives each message in at least one message in sequence, 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.
[0149] 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 of 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 of all messages carrying complete data, so the message and other messages previously cached can be regarded as all messages carrying complete data.
[0150] It can be understood that, in the case where the first data itself is complete data, at least one message generated based on the first data is all messages carrying the complete data. In the case where the first data is only a part of the complete data, at least one message generated based on the first data is only a part of all messages carrying the complete data, and the second communication device can regard the first message and other messages that do not have the first mark and are buffered before the first message as all messages carrying the complete data.
[0151] Step 406: The second communication device parses at least one message to obtain first data carried in the at least one message.
[0152] After the second communication device has received at least one message in sequence, based on the first mark in the last received first message in the at least one message, the second communication device can determine that the first message is the last message carrying complete data, so the second communication device can determine that the first message and other messages cached before the first message (such as the at least one message mentioned above) are all messages carrying complete data. Therefore, the second communication device can trigger parsing of at least one message based on the first mark in the first message, so as to obtain the first data carried in the at least one message.
[0153] It should be noted that, in the case where 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. In the case where the first data is only a part of the complete data, since the first data is the data sent as the last part of the complete data, the second communication device will receive other messages carrying other parts of the complete data in addition to receiving at least one message for carrying the first data. The second communication device can obtain the complete data by parsing the at least one message and other messages carrying other parts of the complete data.
[0154] Specifically, after the protocol stack in the second communication device receives the first message, the protocol stack may determine that the first message is the last message based on the first mark in the first message, so the protocol stack may return other cached messages and the first message (i.e., the at least one message mentioned above) to the application program, so that the application program can parse the at least one message. The protocol stack may return the at least one complete message to the application program, or the protocol stack may strip off the message header in the at least one message and return the first data carried in the at least one message to the application program, and this embodiment does not specifically limit this.
[0155] The above introduces a data transmission method provided in 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.
[0156] For example, see Figure 7 , Figure 7 A schematic diagram of an architecture used in a data transmission method provided in an embodiment of the present application. Figure 7 As shown, the first communication device and the second communication device have the same software architecture, that is, the first communication device and the second communication device include an application, a protocol stack and a protocol stack interface, and a reliable stream transmission protocol is deployed. The software architecture in the first communication device and the second communication device will be described below.
[0157] The first communication device and the second communication device are devices involved in data interaction, for example, they may be terminal devices such as smart phones, personal computers, and laptops, and may also be network devices such as switches and routers.
[0158] Application: A computer program that completes one or more specific tasks on the first communication device and the second communication device. The applications on the first communication device and the second communication device need to exchange data with each other. For example, the applications on the first communication device and the second communication device are both social software programs, and need to exchange data content input by the user through the social software program.
[0159] Protocol stack: A program in an operating system used to send and receive network messages, such as the protocol stack in the Linux kernel.
[0160] Protocol stack interface: The interface provided by the kernel protocol stack to the upper layer (e.g., the application layer where the application program is located), that is, the standard socket interface, such as the commonly used 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 the recv() interface to support the sending and receiving of message semantics.
[0161] 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 small modification is made on the basis of a mature stream transmission protocol (such as TCP) to support message semantics.
[0162] 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.
[0163] The protocol stack interface and reliable stream transmission protocol that have been extended and modified in this embodiment will be described in detail below.
[0164] With respect to the protocol stack interface, in this embodiment, the send() interface and the recv() interface are extended.
[0165] The current send() interface is: ssize_t send(int sockfd, const void*buf, size_tlen, int flags).
[0166] Among them, ssize_t send(int sockfd,const void*buf,size_t len,int flags) is a C language function named send, and defines four parameters of the function. Specifically, int sockfd,const void*buf,size_t len,int flags represent the types of different parameters respectively. The current values of the parameter int flags include MSG_CONFIRM, MSG_DONTROUTE, MSG_DONTWAIT, MSG_EOR, MSG_MORE, MSG_NOSIGNAL, and MSG_OOB.
[0167] In this embodiment, a new value is added to the parameter int flags: MSG_FINISHED, which 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 of the parameter int flags in the send() interface is equivalent to the indication information described in the above embodiment, which is used to indicate that the data transmitted by the current send() interface is the last part of the complete data.
[0168] Among them, each value MSG_XXX in the parameter int flags is a bit (similar to 1, 2, 4, 8, etc., which are powers of 2 and represent a bit in a 32-bit integer). Therefore, in actual extended applications, it is only necessary to define MSG_FINISHED to be different from the existing parameter int flags value.
[0169] For example, assuming that the length of a complete data is 4000 bytes, the application can send a 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.
[0170] send(fd,buf,1000,0); / / Send 1000 bytes without setting a flag
[0171] send(fd,buf,1000,0); / / send another 1000 bytes without setting the flag
[0172] send(fd,buf,1000,0); / / send another 1000 bytes without setting the flag
[0173] send(fd,buf,1000,MSG_FINISHED); / / Send the last 1000 bytes and set the message end mark
[0174] 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 indicating that the protocol stack does not need 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 indicating that the protocol stack needs to set the message end mark when sending the message corresponding to this part of the data.
[0175] In this way, the application does not need to prepare complete data before passing the data to the protocol stack, but can prepare partial data and then pass it to the protocol stack, thereby ensuring the timeliness of data transmission and avoiding data transmission congestion; and, when the application passes the last part of the data, it sets the MSG_FINISHED value to indicate that the data currently being transmitted is the last part of the data, which enables the protocol stack to set the message end mark when sending the message corresponding to this part of the data, so that the receiving communication device can quickly and effectively determine the boundary of the message.
[0176] The current recv() interface is: ssize_t recv(int sockfd,void*buf,size_t len,int flags).
[0177] The recv() interface is a pair with the send() interface mentioned above. The send() interface is used to send data, and the recv() interface is used to receive data.
[0178] In this embodiment, a new value is added to the parameter int flags in the recv() interface: MSG_FULL, which means that a complete message is received before returning.
[0179] Corresponding to the above example of sending a message, the specific method of calling the recv() interface for receiving a message can be:
[0180] recv(fd,buf,5000,MSG_FULL); / / Receive a complete data at one time
[0181] Different from the traditional message receiving interface, the recv() interface of this embodiment provides sufficient flexibility. When the application calls the recv() interface, the MSG_FULL parameter can be set to instruct the protocol stack to return after receiving a complete data. If the MSG_FULL parameter is set, the protocol stack will return data to the application only when it receives a complete data (that is, receives the last message carrying the complete data), and the returned data is a complete data.
[0182] The application can also not set the MSG_FULL parameter when calling the recv() interface. If the MSG_FULL parameter is not set, the performance of the recv() interface is the same as that of the recv() interface of ordinary stream transmission, that is, the protocol stack returns the data to the application as long as it receives it, regardless of whether the data is complete.
[0183] The differences between the reliable stream transmission protocol provided by this embodiment and the reliable stream transmission protocol in the related art will be introduced below.
[0184] 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.
[0185] For example, if an application calls send(fd, buf, 3000, MSG_FINISHED), and the current network MTU is 1000, which means that a message can carry at most 1000 bytes of data. Then, this send() call will trigger the generation of three messages, which means that the protocol stack will encapsulate this part of data into three messages, but only set the message end mark in the last message.
[0186] Difference 2: When the receiving application calls the recv() interface to receive data and sets the MSG_FULL flag, the protocol stack returns data to the application only after receiving a complete set of data; if the MSG_FULL flag is not set, the protocol stack returns data to the application immediately upon receiving the data.
[0187] 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) and the MSG_FULL flag is not set, the protocol stack will block the receiving thread at the recv() call when no data is received; 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.
[0188] Suppose the sending application calls send(fd,buf,3000,MSG_FINISHED) to send a 3000-byte message. If 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 checks the message and finds no message end mark. It will cache the message until the third message is received and the message reception mark is found. Then it will return the complete 3000-byte data to the recv() call.
[0189] 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.
[0190] For example, see Figure 8 , Figure 8 A schematic diagram of a data transmission process provided by an embodiment of the present application. Figure 8 As shown, when the first communication device as a transmitting end sends data to the second communication device as a receiving end, the following steps 801-809 are executed.
[0191] Step 801: An application of a first communication device prepares HTTP header data, where the HTTP header data is complete data.
[0192] Specifically, when the application of the first communication device needs to send an HTTP message to the application of the 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.
[0193] Step 802: The application of the first communication device calls the socket interface to transfer the HTTP header data to the protocol stack, and indicates that the HTTP header data is complete data.
[0194] After preparing the HTTP header data, the application of the first communication device may call a socket interface (such as the send() interface described above) to transfer the HTTP header data to the protocol stack and indicate that the HTTP header data is complete data.
[0195] Exemplarily, 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 indicates that the data of the currently transmitted HTTP header is complete data.
[0196] 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 provided with a message end marker.
[0197] Specifically, the number of messages generated by the protocol stack based on the HTTP header data is related to the data volume of the HTTP header data. The larger the data volume of the HTTP header data, the more messages generated by the protocol stack; the smaller the data volume of the HTTP header data, the smaller the number of messages generated by the protocol stack.
[0198] In addition, since the application indicates that the data of the HTTP header is complete data when passing the HTTP header data 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.
[0199] Step 804 : The application of the first communication device continues to prepare partial data of the HTTP body.
[0200] After the application is ready and passes the HTTP header data to the protocol stack, the application continues to prepare the HTTP body data. In addition, since the HTTP body data is relatively complex, it is often necessary to splice the output data of multiple modules, so the application currently prepares part of the HTTP body data first.
[0201] Step 805 : The application of the first communication device calls the socket interface to transfer partial data of the HTTP body to the protocol stack, and indicates that the partial data of the HTTP body is not complete data.
[0202] 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.
[0203] 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.
[0204] 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, wherein all messages in the at least one message are not provided with a message end marker.
[0205] 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 to all the messages generated to indicate that these messages are not the last of all the messages carrying complete data.
[0206] Step 807: The application of the first communication device continues to prepare the remaining data of the HTTP body.
[0207] Step 808: The application of the first communication device calls the socket interface to transfer 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.
[0208] 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.
[0209] 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 indicates that the data of the HTTP body currently being transmitted is complete data.
[0210] 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 provided with a message end marker.
[0211] Because the application indicates that the remaining data of the HTTP body is the last part of the complete data when passing the remaining data of the HTTP body 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.
[0212] For example, see Fig. 9 , Fig. 9 A schematic diagram of a data receiving process provided by an embodiment of the present application. Fig. 9 As shown, when the second communication device as a receiving end receives data sent by the first communication device as a sending end, it executes the following steps 901-906.
[0213] 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.
[0214] 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 wishes to receive a complete set of data through the parameter value of the recv() interface.
[0215] Exemplarily, 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 is desired to be received.
[0216] Step 902: The protocol stack sequentially receives messages sent by the first communication device.
[0217] 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 each message sent by the first communication device in sequence.
[0218] Step 903: The protocol stack checks whether a message end marker is set in the message header of the received message.
[0219] Step 904: If the message end mark is not set in the message header of the message received by the protocol stack, the received message is cached and subsequent messages are continuously received.
[0220] 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, so the protocol stack caches the received message and continues to receive subsequent messages.
[0221] 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.
[0222] If a message end marker is set in the message header of the message received by the protocol stack, it means that the protocol stack has received the last one 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.
[0223] Step 906: The application processes the received data.
[0224] The above embodiments introduce the data transmission method provided in the embodiments of the present application. The following will introduce the device that executes the above data transmission method.
[0225] See also Fig.10 , Fig.10 A schematic diagram of the structure of a communication device provided in an embodiment of the present application. Fig.10As shown, the communication device includes: an acquisition module 1001, used to acquire first data; a processing module 1002, used to generate 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 1003, used to send at least one message in sequence, 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.
[0226] In a possible implementation, the acquisition module 1001 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.
[0227] In a possible implementation manner, the indication information comes from an application that generates the first data.
[0228] In a possible implementation, the indication information is transmitted by the application through an extended socket interface.
[0229] 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.
[0230] In a possible implementation manner, at least one message is sent based on a stream transmission protocol.
[0231] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0232] See also Fig.11 , Fig.11 This is a schematic diagram of the structure of another communication device provided in an embodiment of the present application. Fig.11 As shown, the communication device includes: a receiving module 1101, used to receive at least one message in sequence, the at least one message includes a first message, the first message is the last received message of 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 of all messages used to carry complete data; a processing module 1102, used to parse at least one message to obtain the first data carried in the at least one message.
[0233] In one possible implementation, the processing module 1102 is also used to: cache each message in at least one message received in sequence; 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 at least one message.
[0234] 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.
[0235] In a possible implementation manner, at least one message is sent based on a stream transmission protocol.
[0236] In a possible implementation manner, the quantity of the at least one message is related to the data volume of the first data.
[0237] Next, an execution device provided by an embodiment of the present application is introduced. Fig.12 , Fig.12 This is a schematic diagram of a structure of an execution device provided in an embodiment of the present application. The execution device 1200 can be specifically a mobile phone, a tablet, a laptop, 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, Fig.12 In the example of FIG. 1 , 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.
[0238] 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 a non-volatile random access memory (NVRAM). The memory 1204 stores processor and operation instructions, executable modules or data structures, or subsets thereof, or extended sets thereof, wherein the operation instructions may include various operation instructions for implementing various operations.
[0239] The processor 1203 controls the operation of the execution device. In a specific application, the various components of the execution device are coupled together through a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus, and a status signal bus, etc. However, for the sake of clarity, various buses are referred to as bus systems in the figure.
[0240] The method disclosed in the above embodiment of the present application can be applied to the processor 1203, or implemented by the processor 1203. The processor 1203 can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 1203. The above processor 1203 can be a general processor, a digital signal processor (digital signal processing, DSP), a microprocessor or a microcontroller, and can further include an application specific integrated circuit (application specific integrated circuit, ASIC), a field programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, 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 processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to execute, or the hardware and software modules in the decoding processor can be combined and executed. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 1204, and the processor 1203 reads the information in the memory 1204 and completes the steps of the above method in combination with its hardware.
[0241] The receiver 1201 can be used to receive input digital or character information, and generate signal input related to the relevant settings and function control of the execution device. The transmitter 1202 can be used to output digital or character information through the first interface; the transmitter 1202 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; the transmitter 1202 can also include a display device such as a display screen.
[0242] In one embodiment of the present application, the processor 1203 is configured to execute Figure 4 The method in the corresponding embodiment.
[0243] 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 end, 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.
[0244] See also Fig.13 , Fig.13 This 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 above Figure 4 The disclosed methods may 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 articles of manufacture.
[0245] Fig.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.
[0246] In one embodiment, the computer readable storage medium 1300 is provided using a signal bearing medium 1301. The signal bearing medium 1301 may include one or more program instructions 1302, which when executed by one or more processors may provide the above-mentioned Figure 4 The functions or parts of the functions described. In addition, Fig.13 Program instructions 1302 in also describe example instructions.
[0247] 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.
[0248] 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, etc. 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, etc.). Thus, for example, the signal bearing medium 1301 may be communicated by a wireless form of the communication medium 1305 (e.g., a wireless communication medium complying with the IEEE 802 standard or other transmission protocol).
[0249] The one or more program instructions 1302 may be, for example, computer executable instructions or logic implementation instructions. In some examples, the computing device of 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 the computer readable medium 1303, the computer recordable medium 1304, and / or the communication medium 1305.
[0250] 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.
[0251] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the 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 site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (Digital Subscriber Line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. 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 a data center that includes one or more available media integration. 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 hard disk Solid State Disk (SSD)), etc.
[0252] Those skilled in the art can 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.
[0253] In the several embodiments provided in the present 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 only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, 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.
[0254] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0255] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0256] 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 to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.
[0257] 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 aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned 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
Cited By
Data transmission method and related apparatus
EP4651473A1
