Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
It should be noted that the terms "comprising" and "having" and any variations thereof in the embodiments of the present application and the accompanying drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus.
It will be understood that the terms first, second, etc. as used herein may be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another element. For example, a first UDP socket may be referred to as a second UDP socket, and similarly, a second UDP socket may be referred to as a first UDP socket, without departing from the scope of the present application. Both the first UDP socket and the second UDP socket are UDP sockets, but they are not the same UDP socket. The term "plurality" as used herein refers to two and more than two. The term "and/or" as used herein refers to one of, or any combination of, the various schemes therein.
The following terms that may be relevant to the present application are explained first:
TCP/IP (Transmission Control Protocol/Internet Protocol ) Protocol refers to a Protocol cluster capable of implementing information transmission between a plurality of different networks, and includes not only TCP Protocol and IP Protocol, but also other protocols such as FTP (FILE TRANSFER Protocol ), SMTP (SIMPLE MAIL TRANSFER Protocol, simple mail transfer Protocol), UDP (User Datagram Protocol ), and the like.
IP address-an unified address format provided by the IP protocol, which specifies the address of the communication for each device on the internet, different network interfaces on one device being assigned different IP addresses.
The TCP protocol is a connection-oriented, reliable and byte stream-based transport layer communication protocol, and has a perfect reliability mechanism.
The UDP protocol is a connectionless, message-oriented transport layer communication protocol, which is only best effort delivery, but does not guarantee reliable delivery.
Physical connection refers to a connection mode established through physical media (such as cables, wireless signals, etc.), and communication is realized through the physical connection by using different electronic devices. Alternatively, the physical connection may include, but is not limited to, a Wi-Fi connection, a bluetooth connection, an ethernet, and the like.
Logical connections-can be understood as virtual connections abstracted over physical connections that can be used to transfer data such that the data transfer does not need to be concerned with the implementation details of the underlying physical.
Socket (Socket) refers to the abstraction of endpoints that perform two-way communication between processes of different electronic devices in a network, one Socket is one end of process communication in the network, and provides a mechanism for processes of an application layer to exchange data by using a network protocol.
The UDP data transmission channels refer to paths for realizing UDP data packet transmission, and in the embodiment of the application, different UDP data transmission channels can correspond to different session identifications, and are mutually independent and not mutually influenced.
The session identifier can be used for identifying UDP data transmission channels, and different UDP data transmission channels can correspond to different session identifiers.
An application, referring to a computer program that typically runs in user mode, typically to interact with a user, in order to accomplish a particular job or jobs.
Services provided by an application refer to functions or capabilities that the application is capable of providing.
Unicast, in which only two entities communicate with each other, and the transmitting end and the receiving end are uniquely determined.
Broadcasting, namely, a one-to-many communication mode, wherein a transmitting end can transmit data to all devices in a network segment.
Multicast, a one-to-many communication method, where a transmitting end can transmit data to all devices added to a group.
At present, interconnection is realized between different electronic devices, a transmission protocol is generally adopted as a TCP protocol, connection established between different electronic devices can be P2P (point-to-point) connection, local area network connection and the like, and when two electronic devices need to perform data transmission (such as file transmission or screen projection) and the like, the P2P connection or the local area network connection can be established and data transmission is performed based on the TCP protocol.
The TCP protocol has a complete reliability mechanism, and an upper application program does not need to consider the problems of packet loss retransmission and the like when using the TCP protocol for data transmission, so that the use cost is low. However, the packet header of the TCP packet is larger, which occupies the bandwidth occupied by the load carried by the TCP packet, so that the transmission efficiency is lower. The congestion control mechanism adopted by the TCP protocol is additive increase and multiplicative decrease, that is, the sending speed is increased additively when no congestion is perceived on the transmission path, and the sending speed is reduced multiplicatively when congestion is perceived on the transmission path, so that in the actual transmission process, the sending speed is difficult to recover to the original transmission capacity after being reduced. The design of the TCP protocol is not intended to be perceived by upper layer applications as network presence, but in actual use, the sender typically needs to know more about the network state to gain greater initiative, thus also contradicting the design of the TCP protocol.
In addition, since the TCP protocol is connection-oriented, once the IP address of the electronic device changes, the TCP connection is broken, affecting data transmission.
Compared with the TCP protocol, under the same transmission condition, the data transmission speed based on the UDP protocol is faster than that based on the TCP protocol, and the occupancy rate of the UDP data packet to the effective bandwidth is higher, so that the transmission efficiency is higher. However, the current UDP protocol has no reliability mechanism and does not meet the requirement of transmission quality.
The embodiment of the application provides a data transmission method, a device, electronic equipment and a computer program product, which can weaken the strong coupling relation between UDP protocol and a network at the bottom layer, can still keep a UDP data transmission channel between two electronic equipment when the network at the bottom layer changes, and improve the stability of data transmission.
Fig. 1 is an application scenario diagram of a data transmission method in one embodiment. As shown in fig. 1, a communication connection may be established between the first electronic device 110 and the second electronic device 120, where the first electronic device 110 and the second electronic device 120 may include, but are not limited to, a mobile phone, a wearable device (such as a smart watch, a smart glasses, etc.), a vehicle-mounted terminal, a tablet computer, a notebook computer, a PC (Personal Computer, a personal computer), a smart home device (such as a television, a sound box, etc.), and so on. Alternatively, any one of the first electronic device 1110 and the second electronic device 120 may be a server.
The manner of communication connection between the first electronic device 110 and the second electronic device 120 may include, but is not limited to, a Wi-Fi connection, a bluetooth connection, etc. Alternatively, the first electronic device 110 and the second electronic device 120 may be directly connected, or may be connected to the same lan, and data transmission may be performed between the first electronic device 110 and the second electronic device 120.
The first electronic device 110 may establish a target UDP data transmission channel with the second electronic device 120, the target UDPUDP data transmission channel corresponding to a target session identification, which may be used to identify the target UDP data transmission channel. The first electronic device 110 may perform UDP packet transmission with the second electronic device 120 through a target UDP data transmission channel, where the UDP packet transmitted by the target UDP data transmission channel carries the target session identifier.
In some embodiments, a plurality of UDP data transmission channels may be established between the first electronic device 110 and the second electronic device 120, different UDP data transmission channels may correspond to different session identifications, and different UDP data transmission channels may be independently controlled and not affect each other.
Note that, the first electronic device 110 may be a data sender or a data receiver, and the second electronic device 120 may be a data sender or a data receiver, and the roles of both are not limited herein.
In the embodiment of the application, UDP communication based on the session identification is realized, the upper application program does not need to sense the network change of the bottom layer when carrying out data transmission, and even if the IP address is changed, as long as the session identification is unchanged, the UDP data transmission channel sensed by the upper application program is not disconnected, the UDP data transmission channel between two electronic devices can still be kept, and UDP data packet transmission is realized through the UDP data transmission channel corresponding to the session identification, thereby improving the stability of data transmission.
As shown in fig. 2, in one embodiment, a data transmission method is provided and can be applied to the first electronic device, where the method may include the following steps:
Step 210, a target UDP data transmission channel is established with the second electronic device, where the target UDP data transmission channel corresponds to a target session identifier, and the target session identifier is used to identify the target UDP data transmission channel.
At least one UDP data transmission channel can be established between the first electronic device and the second electronic device, each UDP data transmission channel can have a corresponding session identifier, the session identifier can be used for identifying the corresponding UDP data transmission channel, and the session identifiers corresponding to different UDP data transmission channels can be different. Illustratively, the session identification may be comprised of one or more of numbers, letters, symbols, and the like.
The target UDP data transmission channel may be one of the at least one UDP data transmission channel, and the target UDP data transmission channel may correspond to the target session identifier.
The UDP data transmission channel may represent a channel for data transmission between one end of the first electronic device to one end of the second electronic device. Alternatively, one end of the first electronic device may be an application program operated by the first electronic device, one end of the second electronic device may be an application program operated by the second electronic device, one end of the first electronic device may be a process operated by the first electronic device, the other end of the second electronic device may be a process operated by the second electronic device, one end of the first electronic device may be a service provided by the application program operated by the first electronic device, and the other end of the second electronic device may be a service provided by the application program operated by the second electronic device.
Further, the UDP data transmission channel may be understood as a logical connection abstracted from a physical connection between the first electronic device and the second electronic device, and may be used to transmit UDP data packets, where logical connections corresponding to different UDP data transmission channels are different, and one logical connection may correspond to one UDP data transmission channel, that is, one logical connection may correspond to one session identifier.
In some embodiments, the target session identification may be determined according to a target service provided by a target application, which may refer to an application responsible for data transmission, the target service may be a service declared or used by the target application, for example, but not limited to, a file exchange service, a screen-drop service, and the like. Further, the target service may be a service in the target application program, which is responsible for data transmission of the target UDP data transmission channel, for example, the target service may be a service in the target application program, which is responsible for sending data through the target UDP data transmission channel, or may be a service in the target application program, which is responsible for processing data received through the target UDP data transmission channel, or the like.
Optionally, the session identifier may be used to characterize different services provided by different applications, where the session identifier is different, and indicates that the application corresponding to the UDP data transmission channel is different and/or that the service provided by the application is different. The UDP communication is carried out based on the session identifier, so that the data can be ensured to be correctly delivered to the service provided by the upper application program, and the accuracy of data transmission is improved. .
The target session identifier may be generated by the first electronic device, the target application may be an application running in the first electronic device, or the target session identifier may be generated by the second electronic device, and the target application may be an application running in the second electronic device.
Further, the target session identifier may be generated according to an application identifier of the target application program, a service identifier of the target service, and a random number.
Wherein the application identification of the target application may be used to identify the target application, which may include, but is not limited to, a package name of an installation package of the target application, a number of the target application, and the like. The service identification of the target service may be used to identify the target service, and the service identification of the target service may include, but is not limited to, a service name of the target service, a number of the target service, and the like.
As a specific implementation manner, hash calculation can be performed on the application identifier of the target application program and the service identifier of the target service according to the random number, so as to obtain the target session identifier. The calculation formula of the destination session identifier may be shown as follows, where sessionid=hash (PAKAGENAME + SERVICENAME), sessionId represents the destination session identifier, PAKAGENAME represents the application identifier of the destination application program, and SERVICENAME represents the service identifier of the destination service.
In the embodiment of the application, the target session identifier is generated according to the application identifier of the target application program, the service identifier of the target service and the random number, so that the session identifiers generated each time are different, the uniqueness of UDP data transmission channels among different electronic devices is ensured, and the accuracy of data transmission is further improved.
It should be noted that, the session identifier may be generated in other manners, and is not limited to the above embodiment.
In some embodiments, for the same service used by the same application program, if multiple data transmission tasks exist or the data volume to be transmitted is relatively large, multiple session identifications may be generated according to the application identification of the application program, the service identification of the service, and multiple random numbers, so that multiple UDP data transmission channels are established between the first electronic device and the second electronic device, and data concurrent transmission may be achieved through the multiple UDP data transmission channels, so that data transmission efficiency is improved.
And 220, carrying out UDP data packet transmission with the second electronic equipment through a target UDP data transmission channel, wherein the UDP data packet transmitted by the target UDP data transmission channel carries a target session identifier.
And the UDP data packets transmitted by the target UDP data transmission channel carry the target session identifier, so that UDP communication based on the session identifier is realized. Further, the first electronic device may send the UDP packet to the second electronic device through the target UDP data transmission channel, or the second electronic device may send the UDP packet to the first electronic device through the target UDP data transmission channel.
In some embodiments, the UDP packet may be sent by broadcast, multicast, unicast, or the like, in a manner of sending the UDP packet between the first electronic device and the second electronic device.
Taking the first electronic device broadcasting the UDP packet as an example, the first electronic device may use a broadcasting address in the local area network to broadcast the UDP packet to each electronic device in the local area network, and when the second electronic device receives the UDP packet broadcast by the first electronic device, the second electronic device may determine that the second electronic device is a receiving end according to the target session identifier carried in the UDP packet, and upload the UDP packet to an application program of an upper layer according to the target session identifier.
Taking the example that the first electronic device sends the UDP packet in a unicast manner, the first electronic device may acquire an IP address and a port number corresponding to the second electronic device, may bind the IP address and the port number with a target UDP data transmission channel, may send the UDP packet to the second electronic device accurately by using the IP address and the port number, and after receiving the UDP packet, the second electronic device may upload the UDP packet to an application program on an upper layer according to a target session identifier carried by the UDP packet.
For the upper application programs in the first electronic device and the second electronic device, because the UDP communication is performed based on the session identifier, the network change of the physical layer, such as IP address change, is not required to be concerned, so long as the target session identifier is unchanged, the target UDP data transmission channel can be always kept for the upper application programs, and the strong coupling relation between the UDP protocol and the network of the bottom layer can be weakened.
In the related art, the TCP protocol has a higher reliability mechanism, and the situation of packet loss and disorder is not expected, if there are multiple packets to be transmitted on one TCP connection at the same time, if the TCP connection is blocked, the transmitted packets are blocked together, and the data transmission efficiency is seriously affected.
In some embodiments of the present application, a plurality of UDP data transmission channels may be established between the first electronic device and the second electronic device, and a plurality of UDP data transmission channels established between the first electronic device and the second electronic device may share a same physical connection, that is, a plurality of UDP data transmission channels established between the first electronic device and the second electronic device may share a same bandwidth of the physical connection, different UDP data transmission channels are independent of each other and may not affect each other, and each UDP data transmission channel may independently control a transmission rate, reliability, and so on, for example, a packet loss or an out-of-order condition occurs in a UDP data packet transmitted by a certain UDP data transmission channel, and normal data transmission of other UDP data transmission channels is not affected. Therefore, a multiplexing transmission mechanism can be realized, and the data transmission efficiency can be improved.
Fig. 3 is a schematic diagram illustrating a UDP data transmission channel established between a first electronic device and a second electronic device in one embodiment. As shown in fig. 3, a plurality of UDP data transmission channels may be established between the first electronic device and the second electronic device, where Session identifiers corresponding to different UDP data transmission channels are different, for example, a Session identifier corresponding to the UDP data transmission channel 302 is Session 1, a Session identifier corresponding to the UDP data transmission channel 304 is Session 2, a Session identifier corresponding to the UDP data transmission channel 306 is Session 3, and the like, but not limited thereto.
In some embodiments, the target UDP data transmission channel may use multiple physical connections for UDP data transmission. Optionally, a physical connection with the highest transmission rate in the plurality of physical connections may be selected, and transmission of the UDP packet corresponding to the target UDP data transmission channel may be implemented through the physical connection with the highest transmission rate. Alternatively, multiple physical connections may be used at the same time to perform parallel transmission of the UDP packet corresponding to the target UDP data transmission channel.
As an implementation manner, one of the physical connections may be selected to transmit the UDP packet corresponding to the target UDP data transmission channel, and if the physical connection is blocked, the physical connection may be switched to another physical connection to continue to transmit the UDP packet corresponding to the target UDP data transmission channel.
In the embodiment of the application, one UDP data transmission channel can use a plurality of physical connections to carry out UDP data transmission, thereby further improving the flexibility and the data transmission efficiency of data transmission.
In the embodiment of the application, the UDP data transmission channels corresponding to the session identifications can be established between different electronic devices, UDP data packet transmission can be realized through the UDP data transmission channels corresponding to the session identifications as long as the session identifications are unchanged, the strong coupling relation between the UDP protocol and the network of the bottom layer can be weakened, and the UDP data transmission channels between the two electronic devices can be still maintained when the network of the bottom layer is changed, so that the stability of data transmission is improved.
As shown in fig. 4, in one embodiment, the step of establishing a target UDP data transmission channel with the second electronic device may include the steps of:
step 402, a target session identification is obtained.
The first electronic device may obtain a target session identification, which may be generated by the first electronic device or by the second electronic device.
In some embodiments, before establishing the UDP data transmission channel, session identifiers generated by both parties may be interacted between the first electronic device and the second electronic device through the target communication connection, so that the first electronic device stores the session identifier generated by the second electronic device, and the second electronic device stores the session identifier generated by the first electronic device, so as to implement information sharing. The first electronic device and the second electronic device can establish UDP data transmission channels corresponding to the session identifications based on the session identifications interacted by the two parties.
As an implementation manner, the target session identifier may be generated by the second electronic device, and the first electronic device may receive the target session identifier sent by the second electronic device through a target communication connection with the second electronic device, and then establish a target UDP data transmission channel based on the target session identifier.
As another implementation manner, the first electronic device may also generate a target session identifier, then send the generated target session identifier to the second electronic device through a target communication connection with the second electronic device, and then establish a target UDP data transmission channel based on the target session identifier.
The target communication connection may include, but is not limited to, a Bluetooth connection, a Wi-Fi connection, and the like.
Optionally, it may be pre-agreed that the session identifier is generated by the data sending end in the first electronic device and the second electronic device, or pre-agreed that the session identifier is generated by the data receiver in the first electronic device and the second electronic device, and specifically, which end generates the session identifier may be flexibly set according to the actual requirement, which is not limited herein.
Before the target UDP data transmission channel is established, the target session identifier can be interacted between the first electronic device and the second electronic device, so that the accurate establishment of the subsequent target UDP data transmission channel can be ensured.
It should be noted that, for a specific manner of generating the target session identifier, reference may be made to the related description in the foregoing embodiment, and a detailed description is not repeated here.
Step 404, based on the target session identification, a first UDP socket is created.
Step 406, establishing a target UDP data transmission channel with a second UDP socket of the second electronic device through the first UDP socket, wherein the second UDP socket is created by the second electronic device based on the target session identifier.
The first electronic device may create a first UDP socket based on the target session identification, the first UDP socket may correspond to the target session identification, and may be operable to enable communication with a second UDP socket of the second electronic device.
The second electronic device may also create a second UDP socket based on the target session identification, the second UDP socket may correspond to the target session and may be operable to enable communication with the first UDP socket of the first electronic device.
Illustratively, the first UDP socket created by the first electronic device may be described as SeekerSocket (AF_INENT, SOCK_ DGRAM, sessionId). The af_interval may be used to characterize a communication protocol or a protocol family to which the communication protocol belongs, for example, the communication protocol used by the af_interval may be a customized UDP protocol provided by an embodiment of the present application. SOCK_ DGRAM may be used to characterize the socket type, e.g., the SOCK_ DGRAM characterizes that the first UDP socket belongs to the datagram socket type. SessionId may be used to characterize the session identity, e.g., the SessionId characterizes the target session identity to which the first UDP socket corresponds.
Illustratively, the second UDP socket created by the second electronic device may be described as providerSocket (AF_INENT, SOCK_ DGRAM, sessionId). The af_interval may be used to characterize a communication protocol or a protocol family to which the communication protocol belongs, for example, the af_interval may characterize a customized UDP protocol provided by an embodiment of the present application, where the communication protocol used by the second UDP socket may be a customized UDP protocol. SOCK_ DGRAM may be used to characterize the socket type, e.g., the SOCK_ DGRAM characterizes that the second UDP socket belongs to the datagram socket type. SessionId may be used to characterize the session identity, e.g., the SessionId characterizes the target session identity to which the second UDP socket corresponds.
The sessionId in the first UDP socket is the same as the sessionId in the second UDP socket, so that a target UDP data transmission channel can be established between the first UDP socket and the second UDP socket, and the transmission of UDP data packets between the first UDP socket and the second UDP socket is realized. An application program in the first electronic device can send a UDP data packet carrying the target session identifier through the first UDP socket, the UDP data packet can be received by the second electronic device, and the application program of the second electronic device can read data carried in the UDP data packet through the second UDP socket. Similarly, the application program in the second electronic device may also send a UDP packet carrying the target session identifier through the second UDP socket, where the UDP packet may be received by the first electronic device, and the application program of the first electronic device may read data carried in the UDP packet through the first UDP socket. .
In some embodiments, after creating the first UDP socket, the first electronic device may send a first request signal over the first UDP socket, where the first request signal may be used to instruct the second electronic device to receive the first request signal over the second UDP socket and to feed back the first response signal. The second electronic device may receive, through the second UDP socket, the first request signal sent by the first electronic device through the first UDP socket, and send, through the second UDP socket, the first response signal to the first electronic device. The first electronic device can receive a first response signal sent by the second electronic device through the first UDP socket, and a target UDP data transmission channel between the first UDP socket and the second UDP socket is established.
As an implementation manner, after the first UDP socket is created, the first electronic device may generate a first request signal carrying the first IP address and the first port number of the second electronic device, and the target session identifier, and send the first request signal to the second UDP socket of the second electronic device through the first UDP socket. The first port number may be bound to an application in the second electronic device (e.g., the target application in the above-described embodiments) or to a process of the application. The first port number may be customized by the application of the second electronic device or may be allocated by the system, or the first port number may be a fixedly set port number, which is not limited herein.
Because the first request signal carries the first IP address, the first port number and the target session identifier of the second electronic device, the second electronic device can accurately receive the first request signal through the second UDP socket. The second electronic device may read the first request signal sent by the first electronic device from the second UDP socket and send a first response signal to the first UDP socket via the second UDP socket.
Further, the first request signal sent by the first electronic device may further carry the second IP address and the second port number of the first electronic device. The second electronic device may acquire the second IP address and the second port number of the first electronic device according to the first request signal, generate a first response signal carrying the second IP address and the second port number of the first electronic device and the target session identifier, and send the first response signal to the first UDP socket through the second UDP socket. Because the first response signal carries the second IP address, the second port number and the target session identifier of the first electronic device, the first electronic device can accurately receive the first response signal through the first UDP socket.
As an implementation manner, after the first electronic device reads the first response signal from the first UDP socket, a logical connection based on the target session identifier may be initiated to the second electronic device, and in a process of establishing the logical connection corresponding to the target session identifier, both parties may perform processes such as identity authentication, service synchronization, information synchronization, and negotiation, so as to complete establishment of the target UDP data transmission channel.
It should be noted that any one of the UDP data transmission channels between the first electronic device and the second electronic device may be established by using the manner of establishing the target UDP data transmission channel described in the foregoing embodiment. Different UDP data transmission channels can be established based on the corresponding session identification, so that independent control of each UDP data transmission channel can be realized. .
Illustratively, fig. 5 is a timing diagram of establishing a UDP data transmission channel in one embodiment. As shown in fig. 5, the second electronic device may generate a session identifier sessionid=hash (PAKAGENAME + SERVICENAME) and transmit the session identifier to the first electronic device. The second electronic device may determine a port number port=x, which may be application-customized. The second electronic device may create a UDP socket providerSocket (af_interval, dock_ DGRAM, sessionId). The first electronic device may create a UDP socket SeekerSocket (af_interval, dock_ DGRAM, sessionId). The first electronic device may create a datagram with the IP address providerIP and port number port=x of the second electronic device and send the datagram to providerSocket of the second electronic device via SeekerSocket. The second electronic device may read the UDP segment from providerSocket and send a response message to SeekerSocket of the first electronic device via providerSocket. The first electronic device may read the datagram (i.e., the response message) from SeekerSocket and send the SessionId-based logical connection.
The first electronic device sends the first request signal through the first UDP socket created, receives the first request signal at the second UDP socket created by the second electronic device and feeds back the first response signal, so that the accuracy of data transmission through a target UDP data transmission channel between the first UDP socket and the second UDP socket can be ensured.
In the embodiment of the application, the first electronic equipment can establish the first UDP socket based on the target session identifier, the second electronic equipment can establish the second UDP socket based on the target session identifier, the first electronic equipment can establish the target UDP data transmission channel through the first UDP socket and the second UDP socket of the second electronic equipment, the UDP sockets corresponding to different UDP data transmission channels are different, the different UDP data transmission channels cannot be mutually influenced, the independent transmission control of each UDP data transmission channel can be realized, multiplexing can be realized, and the flexibility and the transmission efficiency of data transmission are improved.
In the related art, the TCP protocol specifies that a transmitting end transmits a data packet, a receiving end replies an ACK signal (acknowledgement information) when correctly receiving the data packet, and the transmitting end continues to transmit the next data packet when receiving the ACK signal replied by the receiving end. The TCP protocol also adopts a data transmission mode of a sliding window, a transmitting end can transmit a plurality of data packets contained in the current window, a receiving end replies corresponding ACK signals when correctly receiving one data packet, the transmitting end waits for receiving the ACK signals of all the data packets in the current window and can slide to the next window to continue the data packet transmission of the next window.
Although this communication mechanism guarantees the reliability of data transmission, ambiguity also exists. For example, the transmitting end sends the data packet with the sequence number of 3 first and sends the data packet with the sequence number of 5, disorder or packet loss occurs in the transmission process, the receiving end receives the data packet with the sequence number of 5 first, but does not receive the data packet with the sequence number of 3, and the transmitting end retransmits the data packet with the sequence number of 3 due to the fact that the transmitting end does not receive the ACK signal corresponding to the data packet with the sequence number of 3 after overtime. The receiving end receives the data packet with the sequence number of 3 at a certain moment and replies the corresponding ACK signal, but the receiving end does not know whether the received data packet with the sequence number of 3 is the data packet with the sequence number of 3 sent by the sending end for the first time or the retransmitted data packet with the sequence number of 3, and the sending end cannot distinguish whether the data packet with the sequence number of 3 sent by the sending end for the first time or the retransmitted data packet with the sequence number of 3 corresponding to the ACK signal, so that ambiguity exists. Furthermore, RTT (Round-Trip Time) calculated by the transmitting end according to the ACK signal is also inaccurate.
The UDP protocol provided by the embodiment of the application can customize the transmission mechanism and the reliability mechanism of the UDP protocol. The UDP protocol provided by the embodiment of the application can reserve a transmission confirmation mechanism and retransmit the UDP data packet with packet loss so as to ensure the reliability of data transmission.
As shown in fig. 6, in some embodiments, the method may further include the steps of:
In step 602, a target UDP packet that needs to be retransmitted is determined.
The first electronic device may be a data transmitting end, and the second electronic device may be a data receiving end.
In the process that the first electronic device sends the UDP data packet to the second electronic device through the target UDP data transmission channel, the target UDP data packet to be retransmitted may be determined, where the target UDP data packet to be retransmitted may refer to a UDP data packet that is sent by the first electronic device, but not received by the second electronic device, for example, a UDP data packet that is lost due to a network condition, and so on. .
In the embodiment of the application, the UDP protocol may have a transmission acknowledgement mechanism, and after the second electronic device receives the UDP packet sent by the first electronic device, the second electronic device may reply an acknowledgement signal to the first electronic device, so that the first electronic device determines, according to the acknowledgement signal, that the second electronic device receives the UDP packet sent by the first electronic device. Therefore, the target UDP packet that needs to be retransmitted may be a UDP packet in which the first electronic device does not receive the corresponding acknowledgement signal.
In step 604, a target packet sequence number is allocated to the target UDP packet, where the target packet sequence number may be a next packet sequence number of the packet sequence number carried by the UDP packet that was last transmitted.
In some embodiments, in order to achieve reliable transmission, the UDP packet sent by the first electronic device may further carry a packet sequence number, where the packet sequence number may be used to characterize the transmission sequence corresponding to the UDP packet. For example, the UDP packet transmitted by the target UDP data transmission channel may carry a target session identifier and a packet sequence number, where the packet sequence number may be used to characterize a corresponding transmission sequence of the UDP packet in the target UDP data transmission channel. For example, packet sequence numbers may be sequentially allocated to UDP packets transmitted from 1 to the target UDP data transmission channel. The packet sequence numbers are allocated to the UDP data packets, so that the reliability of data transmitted by the UDP data transmission channels can be improved, further, the packet sequence numbers can be independently allocated to the transmitted UDP data packets by each UDP data transmission channel, the mutual influence is avoided, and the accuracy of data transmission is further ensured.
Further, when the UDP packet retransmission occurs, the repeated packet sequence numbers are not used, but are sequentially accumulated in order. After determining the target UDP packet to be retransmitted, the next packet sequence number of the packet sequence number corresponding to the UDP packet that is most recently transmitted by the target UDP data transmission channel may be determined as the target packet sequence number, and the target packet sequence number may be allocated to the target UDP packet.
And step 606, transmitting the target UDP data packet carrying the target packet sequence number to the second electronic device through the target UDP data transmission channel.
The first electronic device can send the target UDP data packet carrying the target packet sequence number to the second electronic device through the target UDP data transmission channel, and further, the first electronic device can send the target UDP data packet carrying the target packet sequence number to the second UDP socket of the second electronic device through the first UDP socket, so that retransmission of the target UDP data packet is realized.
As an embodiment, the transmission acknowledgement mechanism of the UDP protocol of the present application may be that the data receiving end replies an acknowledgement signal to each received UDP packet. The first electronic equipment sends a first UDP data packet through a target UDP data transmission channel, if a confirmation signal sent by the second electronic equipment is not received within a first time length for sending the first UDP data packet, the first UDP data packet is determined to be the target UDP data packet needing to be retransmitted, and the confirmation signal is used for indicating the second electronic equipment to receive the first UDP data packet. The first electronic device can allocate a target packet sequence number to the target UDP data packet, and send the target UDP data packet carrying the target packet sequence number to the second electronic device through the target UDP data transmission channel, so that the retransmission of the data packet is realized, and the reliability of data transmission can be ensured.
Fig. 7 is a schematic diagram illustrating retransmission of UDP packets in one embodiment. As shown in fig. 7, the first electronic device sends a UDP packet 1 to the second electronic device through the target UDP data transmission channel, and after receiving the UDP packet 1, the second electronic device feeds back an acknowledgement signal 1 through the target UDP data transmission channel. The first electronic device receives the confirmation signal 1 through the target UDP data transmission channel, continues to send the UDP data packet 2, does not feed back the confirmation signal 2 when the second electronic device does not receive the UDP data packet 2 due to packet loss, and resends the UDP data packet 2 through the target UDP data transmission channel when the second electronic device does not receive the confirmation signal 2 after overtime.
In some embodiments, the transmission acknowledgement mechanism of the UDP protocol of the present application may be that the data receiving end replies an acknowledgement signal after each received target number of UDP packets, where the acknowledgement signal is not used to drive the sliding window to slide, but is only used to inform the data sending end whether there is a packet loss.
The target number may be understood as the number of UDP packets corresponding to the acknowledgement signal sent by the data receiving end, or may refer to the number of UDP packets received by the data receiving end for each handover to an upper application program. And under the condition that the second electronic equipment successfully receives the target number of UDP data packets sent by the first electronic equipment through the target UDP data transmission channel, uploading the target number of UDP data packets to a target application program corresponding to the target UDP data transmission channel.
Alternatively, the target number of UDP packets uploaded to the upper layer target application may be out of order, and the order accuracy of the UDP packets need not be guaranteed. Illustratively, fig. 8 is a schematic diagram of uploading UDP packets in one embodiment. For example, if the target number is 4, if the 6 th UDP packet between the 4 th UDP packet and the 7 th UDP packet is out of order or lost, the 6 th UDP packet is not received, but the 8 th UDP packet is received, the 4 th UDP packet, the 5 th UDP packet, the 7 th UDP packet and the 8 th UDP packet may be uploaded to the upper layer target application together, and the 6 th UDP packet may be uploaded to other UDP packets in the next batch. By adopting the mode, the condition of transmission congestion can be reduced and the data transmission efficiency can be improved without waiting like TCP transmission.
Further, since the transmission and uploading of the UDP packet may be disordered, in order to ensure that the target application at the upper layer accurately unpacks and assembles the UDP packet, data information may be added to the header of the UDP packet, where the data information may be used to indicate a data position or a data sequence number corresponding to the payload carried by the UDP packet, so as to help the target application of the second electronic device to recover the data received by the target application.
In some embodiments, the acknowledgement signal fed back by the data receiving end may be used to acknowledge the reception of the target number of UDP packets, so that the transmission may be changed from streaming to block transmission. The first electronic device may send a target number of second UDP packets, which may be understood as a packet group or block, to the second electronic device via the target UDP data transmission channel. If the second electronic device successfully receives the target number of UDP packets sent by the first electronic device through the target UDP data transmission channel, an acknowledgement signal may be sent to the first electronic device, where the acknowledgement signal may be used to indicate that the second electronic device receives the target number of second UDP packets. If the first electronic device receives the acknowledgement signal, the next set of UDP packets of the target number may be sent.
In the case where there is a packet loss in the target number of UDP packets, the second electronic device may not send an acknowledgement signal to the first electronic device. If the first electronic device does not receive the acknowledgement signal sent by the second electronic device within a first duration after the second UDP data packets with the target number are sent, determining that the second UDP data packets with the target number are target UDP data packets needing to be retransmitted. The target number of target UDP packets may be sequentially allocated with a corresponding target packet sequence number, where the target packet sequence number corresponding to the target number of target UDP packets may be sequentially accumulated based on the packet sequence number corresponding to the last UDP packet to be sent (e.g., the packet sequence number of the last second UDP packet to be sent in the second UDP packet of the target number), and may not be repeated with the packet sequence number of the second packet to be sent previously.
The first electronic device may send the target number of target UDP packets to the second electronic device through the target UDP data transmission channel, and the second electronic device may discard the second UDP packets received before, and may upload the target number of target UDP packets to the target application after successfully receiving the target number of target UDP packets, and may also feedback a confirmation signal to the first electronic device.
Fig. 9 is a schematic diagram illustrating retransmission of UDP packets in another embodiment. As shown in fig. 9, the first electronic device sends a target number of UDP packets, for example, a target number of 4, to the second electronic device through the target UDP data transmission channel, and the first electronic device sends UDP packets 1 to 4. And after receiving the UDP data packets 1-4, the second electronic equipment feeds back the confirmation signal 1 through the target UDP data transmission channel. The first electronic device receives the confirmation signal 1 through the target UDP data transmission channel, continuously transmits the UDP data packets (UDP data packets 5-UDP data packets 8) with the target number, and does not feed back the confirmation signal 2 when the second electronic device does not fully receive the UDP data packets 5-UDP data packets 8 due to packet loss, and retransmits the UDP data packets 5-UDP data packets 8 through the target UDP data transmission channel when the second electronic device does not receive the confirmation signal 2 after overtime.
In the embodiment of the application, whether the UDP data packets with the target number are sent or not is confirmed through the confirmation signal, and retransmission is carried out under the condition of packet loss, so that the stability of data transmission can be improved, each UDP data packet is not required to be confirmed, the information interaction between two electronic devices can be reduced, the expenditure is reduced, and the data transmission efficiency is improved.
In some embodiments, the target number may be determined according to a latency requirement corresponding to the target UDP data transmission channel. Under the condition that the delay requirement corresponding to the target UDP data transmission channel is higher, namely the real-time requirement of the transmission service corresponding to the target UDP data transmission channel is higher, the target quantity can be smaller, and the real-time performance of data transmission is ensured. If the delay requirement corresponding to the target UDP data transmission channel is smaller, namely, the real-time requirement of the transmission service corresponding to the target UDP data transmission channel is lower, the target quantity can be properly increased, so that the transmission cost can be reduced.
Under the condition that a plurality of UDP data transmission channels are established between the first electronic device and the second electronic device, the target number corresponding to different UDP data transmission channels can be determined according to the time delay requirement corresponding to each UDP data transmission channel, and each UDP data transmission channel can flexibly control the flow. Fig. 10 is a schematic diagram illustrating flow control performed by multiple UDP data transmission channels independently in one embodiment. As shown in fig. 10, 3 UDP data transmission channels may be established between the first electronic device and the second electronic device, and Session identifiers corresponding to the first electronic device and the second electronic device are Session1, session2, and Session3, respectively. The number of UDP data transmission channels corresponding to Session1 may be 4, the number of UDP data transmission channels corresponding to Session2 may be 6, the number of UDP data transmission channels corresponding to Session3 may be 2, etc., but not limited thereto.
As an embodiment, the target number may be determined by an upper layer application, for example, the target number corresponding to the target UDP data transmission channel, and may be determined by the target application and transferred to the peer when the target UDP data transmission channel is established. As another embodiment, the target number may be determined by negotiating by the two electronic devices when the target UDP data transmission channel is established, so that the determined target number conforms to the data transmission capability of the two electronic devices.
In the embodiment of the application, when the retransmission of the UDP data packet occurs, repeated packet sequence numbers are not used, and the packet sequence numbers are accumulated in sequence, so that the ambiguity problem can be avoided, the first electronic device and the second electronic device do not need to pay attention to whether the UDP data packet is transmitted for the first time or retransmitted, and the accuracy of RTT calculated by using the confirmation signal can be ensured.
In some embodiments, the customized UDP protocol provided by the embodiments of the present application may implement connection migration, and an application on an upper layer need not care about a change of a bottom layer network, but only needs to care about a session identifier corresponding to a UDP data transmission channel. When the network changes, the upper application program only needs to pay attention to the data sent before the network changes (such as abnormal disconnection of the network, disconnection of communication connection caused by IP address change, and the like), and continues to send the data after the bottom network is restored.
As shown in fig. 11, the method may further include the following steps:
In step 1102, a broadcast signal is transmitted in the event that the communication connection between the first electronic device and the second electronic device is broken.
In some embodiments, the connection unit of the customized UDP protocol provided by the embodiments of the present application may include a session identifier, and compared with the connection unit of a quad, a six-tuple, etc. in the TCP protocol, as long as the session identifier is unchanged, an application program at an upper layer will not perceive disconnection of the UDP data transmission channel even if the IP address at the bottom layer changes.
The disconnection of the communication between the first electronic device and the second electronic device may be caused by an abnormality in the underlying network, may be caused by a change in the IP address of the first electronic device or the second electronic device, or may be caused by an excessive distance between the first electronic device and the second electronic device, and the case of the disconnection of the communication is not limited here.
As an embodiment, the first electronic device may detect whether the physical connection with the second electronic device is broken, and if the physical connection with the second electronic device is detected to be broken, it may be determined that the communication connection between the first electronic device and the second electronic device is broken.
As another embodiment, the first electronic device may also determine that the communication connection between the first electronic device and the second electronic device is disconnected if the number of retransmissions of the UDP packet over the target UDP data transmission channel reaches the preset threshold, which indicates that the UDP packet sent by the first electronic device over the target UDP data transmission channel cannot be successfully received by the second electronic device.
In the event that the communication connection between the first electronic device and the second electronic device is broken, the first electronic device may send a broadcast signal that may carry the target session identification, such that the second electronic device may feedback the second response signal in the event that the communication connection between the first electronic device and the second electronic device is restored.
Under the condition that the communication connection between the first electronic equipment and the second electronic equipment is disconnected, the first electronic equipment does not determine whether the network information (such as an IP address and the like) of the second electronic equipment changes, so that the first electronic equipment can send a broadcast signal carrying the target session identifier in a broadcast mode. The broadcast signal may function to search for the second electronic device, and the second electronic device may receive the broadcast signal transmitted by the first electronic device in case that the communication connection between the first electronic device and the second electronic device is restored.
The second electronic device can compare the target session identifier carried in the broadcast signal with a plurality of session identifiers existing in the second electronic device, and if the comparison is successful, the second electronic device can send a second response signal to the first electronic device.
Step 1104 receives a second response signal sent by a second electronic device.
In the case where the communication connection between the first electronic device and the second electronic device is restored, the second electronic device may receive the broadcast signal transmitted by the first electronic device. The second electronic device may parse the received broadcast signal to extract the target session identifier carried in the broadcast signal. The second electronic device can compare the target session identifier with session identifiers respectively corresponding to a plurality of existing UDP sockets, and if the comparison is successful, the second electronic device establishes a target UDP data transmission channel corresponding to the target session identifier with the first electronic device before the second electronic device is indicated, then a second response signal can be sent to the first electronic device.
And step 1106, continuing to transmit the UDP data packets with the second electronic device through the target UDP data transmission channel.
After the first electronic device receives the second response signal sent by the second electronic device, the first electronic device can confirm that the communication connection between the first electronic device and the second electronic device is reestablished, and then the first electronic device can continue to transmit UDP data packets with the second electronic device through the target UDP data transmission channel.
Illustratively, FIG. 12 is a timing diagram for implementing connection migration between two electronic devices in one embodiment. As shown in fig. 12, the first electronic device transmits part of data to the second electronic device through the target UDP data transmission channel. In the case that the communication connection between the first electronic device and the second electronic device is disconnected, the first electronic device may broadcast Seeker hello a message, where the Seeker hello message carries a target session identifier SessionId corresponding to the target UDP data transmission channel. Under the condition that the first electronic equipment successfully recovers the communication connection with the second electronic equipment, the second electronic equipment can successfully receive Seeker hello messages broadcast by the first electronic equipment, the SessionId carried in the Seeker hello messages can be used for traversing the session identifier existing in the second electronic equipment, and if the comparison is successful, a second response signal can be returned to the first electronic equipment. Further, if the comparison is successful, the second electronic device may store the current information such as the second IP address and the second port number of the first electronic device, and the first electronic device may receive the second response signal, or may obtain the current information such as the first IP address and the first port number of the second electronic device according to the second response signal, and continue the data transmission interrupted before through the target UDP data transmission channel.
In the embodiment of the application, under the condition that the communication connection between the two electronic devices is disconnected, the first electronic device can send a broadcast signal, the broadcast signal carries the target session identifier, the second electronic device can receive the broadcast signal and identify the target session identifier as long as the communication connection between the two electronic devices is restored, and the second electronic device can continuously communicate based on the target session identifier, even if the information such as the IP address of the bottom layer changes, the information can be updated in time, and for an application program of the upper layer, the UDP data transmission channel between the two electronic devices is still maintained, so that the relation of strong coupling with the bottom layer in the original transmission protocol can be stripped, and the stability of data transmission is improved.
In some embodiments, the customized UDP protocol provided by the embodiments of the present application further has an encryption mechanism, so as to implement secure transmission of data. The first electronic device may negotiate a transmission key corresponding to the target UDP data transmission channel with the second electronic device before transmitting the UDP data packet with the second electronic device via the target UDP data transmission channel. The transmission key can be used for encrypting and decrypting the data transmitted by the target UDP data transmission channel.
Alternatively, the data transmitted by the target UDP data transmission channel may be encrypted and decrypted using an asymmetric encryption algorithm, and the transmission key may include a target public key and a target symmetric key, where the target public key may be used to decrypt the data transmitted by the target UDP data transmission channel and the target symmetric key may be used to encrypt the data transmitted by the target UDP data transmission channel.
In some embodiments, in the case that the first electronic device and the second electronic device first establish the UDP data transmission channel, a temporary key may be negotiated with the second electronic device, and then, based on the temporary key, a transmission key corresponding to the target UDP data transmission channel may be negotiated with the second electronic device.
The first time the first electronic device and the second electronic device establish the UDP data transmission channel may refer to a case where the first electronic device has not previously established the UDP data transmission channel with the second electronic device, or the first electronic device and the second electronic device have previously established the UDP data transmission channel, but have not stored device information corresponding to the second electronic device, or stored device information fails, or the like.
Under the condition that the first electronic device and the second electronic device establish the UDP data transmission channel for the first time, two rounds of encryption negotiation can be conducted between the first electronic device and the second electronic device, wherein the first round can generate a temporary key, and the second round can generate a transmission key based on the temporary key generated in the first round.
As a specific embodiment, in the case that the first electronic device and the second electronic device establish the UDP data transmission channel for the first time, the second electronic device may randomly generate the prime number p and the primitive root q of the prime number p, and may randomly generate a random number C pro within a preset numerical range (for example, within a range of 1 to 2 32), and may generate the first key C pub according to the prime number p, the primitive root q and the random number C pro, for example,The first electronic device may package the first key C pub, prime number p, and primitive root q as configuration information (config) to the first electronic device.
Further, after the first electronic device creates the first UDP socket, the first electronic device may send a first request signal to the second electronic device, for example, the first request signal may be Seeker hello a message, and after the second electronic device receives the first request signal, and confirms that the first electronic device first establishes a UDP data transmission channel with the first electronic device, the first key C pub, the prime number p, and the primitive root q may be generated, and send a first response signal carrying configuration information to the second electronic device.
After receiving the configuration information sent by the second electronic device, the first electronic device may randomly generate a random number C se within a preset numerical range (for example, within the range of 1·2 32), and generate a temporary public key C c_pub and a temporary symmetric key C1 according to the first key C pub, the prime number p, the primitive root q, and the random number C se. Illustratively, the temporary public keyTemporary symmetric key
The first electronic device may acquire interaction data, which may include device information, connection information, etc. of the first electronic device, for example, may include a device model number, a MAC (MEDIA ACCESS Control Address) Address, an IP Address, etc. of the first electronic device, but is not limited thereto. The first electronic device may encrypt the interaction data with the temporary symmetric key, the encryption function of which may be characterized as encryption (C 1, data), wherein data represents the interaction data. The first electronic device may send the encrypted interaction data and the temporary public key C c_nub to the second electronic device.
After receiving the encrypted interaction data and the temporary public key C c_pub, the second electronic device may verify the temporary public key C c_pub, for example, the temporary public key C c_pub may be verified by using the following formula:
Under the condition of successful verification, the encrypted interaction data can be decrypted by using the temporary public key to obtain the interaction data, and the interaction data is stored.
The first electronic device may regenerate a new random number C t_se, generate the target public key and the target symmetric key in the same manner as the temporary public key and the temporary symmetric key, and send the newly generated target public key to the second electronic device. In the process that the first electronic device performs data transmission with the second electronic device through the target UDP data transmission channel, the first electronic device can encrypt the UDP data packet according to the target symmetric key and send the encrypted UDP data packet to the second electronic device through the target UDP data transmission channel, and the second electronic device can decrypt the encrypted UDP data packet by using the target public key, so that data security transmission is realized.
Illustratively, fig. 13A is a timing diagram of two electronic devices first establishing a UDP data transmission channel in one example. As shown in fig. 13A, in the case where the first electronic device and the second electronic device establish the UDP data transmission channel for the first time, the first electronic device may send Seekerhello a message to the second electronic device, the second electronic device may receive the Seekerhello message and reply to the configuration information (config), and the first electronic device may generate a temporary public key and a temporary symmetric key according to the configuration information, encrypt the interaction data according to the temporary symmetric key, and then send the encrypted interaction data and the temporary public key to the second electronic device. The second electronic device may verify the temporary public key, decrypt the encrypted interaction data, and then store the decrypted interaction data. The first electronic device can regenerate the target public key and the target symmetric key according to the configuration information, the first electronic device can send the target public key to the second electronic device, and the first electronic device and the second electronic device can realize safe data transmission in the UDP data transmission channel based on the target public key and the target symmetric key.
In the above embodiment, under the condition that the first electronic device and the second electronic device establish the UDP data transmission channel for the first time, two rounds of key negotiation may be performed, where the temporary key of the first round of negotiation may be used to encrypt and decrypt the interactive data, and the transmission key of the second round of negotiation may be used to encrypt and decrypt the transmitted UDP data packet, so that the security of data transmission is ensured.
In some embodiments, in the case that the first electronic device and the second electronic device do not establish the UDP data transmission channel for the first time, the transmission key corresponding to the target UDP data transmission channel may be negotiated with the second electronic device based on the stored temporary key.
Under the condition that the first electronic device and the second electronic device do not establish the UDP data transmission channel for the first time, the first electronic device stores configuration information corresponding to the second electronic device, and the first electronic device and the second electronic device store device information, connection information and the like of each other, so that the temporary secret key can be no longer required to be regenerated. The first electronic device regenerates a new random number, generates a target public key and a target symmetric key in the same manner as the temporary public key and the temporary symmetric key, and transmits the newly generated target public key to the second electronic device.
Further, after creating the first UDP socket, the first electronic device may send a first request signal to the second electronic device, for example, the first request signal may be a Seeker hello message, where the first request signal may carry the target public key generated by the first electronic device.
Optionally, the second electronic device may verify the received target public key, and the method for verifying the target public key is similar to the method for verifying the temporary public key described in the foregoing embodiment, which is not repeated herein.
Under the condition that the target public key is successfully checked, the target public key and the target symmetric key can be based on the target public key and the target symmetric key to realize the safe data transmission in the UDP data transmission channel. The first electronic device may encrypt the UDP packet according to the target symmetric key, and send the encrypted UDP packet to the second electronic device through the target UDP data transmission channel, and the second electronic device may decrypt the encrypted UDP packet using the target public key.
Illustratively, fig. 13B is a timing diagram of two electronic devices not first establishing a UDP data transmission channel in one example. As shown in fig. 13B, in the case where the first electronic device and the second electronic device do not establish the UDP data transmission channel for the first time, the first electronic device may generate the target public key and the target symmetric key according to the stored configuration information, the first electronic device may send Seeker hello a message to the second electronic device, where the Seeker hello message carries the target public key, and the second electronic device receives Seeker hello the message and may store the target public key. The two can realize the safe data transmission in the UDP data transmission channel based on the target public key and the target symmetric key.
In this embodiment, under the condition that the first electronic device and the second electronic device do not establish the UDP data transmission channel for the first time, a round of key negotiation may be directly performed to determine a transmission key corresponding to the target UDP data transmission channel, so that overhead may be reduced and time consumed for establishing the target UDP data transmission channel may be reduced while secure data transmission is ensured.
In some embodiments, for different UDP data transmission channels, respective corresponding transmission keys may be generated, and the generated transmission keys may be bound to session identifiers of the UDP data transmission channels, so that secure data transmission of each UDP data transmission channel may be achieved.
In the embodiment of the application, an encryption mechanism of the UDP protocol is provided, and the safe data transmission through the UDP data transmission channel can be realized.
As shown in fig. 14, in one embodiment, another data transmission method is provided and can be applied to the second electronic device, where the method may include the following steps:
Step 1410, a target UDP data transmission channel is established with the first electronic device, where the target UDP data transmission channel corresponds to a target session identifier, and the target session identifier is used to identify the target UDP data transmission channel.
In step 1420, the target UDP packet is transmitted with the first electronic device via the target UDP data transmission channel, where the UDP packet transmitted by the target UDP data transmission channel carries the target session identifier.
In some embodiments, step 1410 may include obtaining a target session identification, creating a second UDP socket based on the target session identification, and establishing a target UDP data transfer path with a first UDP socket of the first electronic device through the second UDP socket, the first UDP socket created by the first electronic device based on the target session identification.
In some embodiments, the step of establishing a target UDP data transmission channel with a first UDP socket of the first electronic device through the second UDP socket comprises receiving a first request signal sent by the first electronic device through the first UDP socket through the second UDP socket, and sending a first response signal to the first electronic device through the second UDP socket to enable the first electronic device to receive the first response signal through the first UDP socket and establish the target UDP data transmission channel between the first UDP socket and the second UDP socket.
In some embodiments, the step of obtaining the target session identification includes receiving a target session identification sent by the first electronic device over a target communication connection with the first electronic device, the target session identification being generated by the first electronic device. Or the step of obtaining the target session identification comprises generating the target session identification, and the method further comprises sending the generated target session identification to the first electronic device through a target communication connection with the first electronic device.
In some embodiments, the method further includes uploading the target number of UDP data packets to a target application program corresponding to the UDP data transmission channel under the condition that the target number of UDP data packets sent by the first electronic device are successfully received through the target UDP data transmission channel.
In some embodiments, the method further comprises sending an acknowledgement signal to the first electronic device if the target number of UDP packets sent by the first electronic device are successfully received through the target UDP data transmission channel, and/or not sending an acknowledgement signal to the first electronic device if there is a packet loss in the target number of UDP packets, so that the first electronic device resends the target number of UDP packets.
In some embodiments, the method further includes receiving a broadcast signal sent by the first electronic device, where the broadcast signal carries a target session identifier, where the broadcast signal is sent by the first electronic device when communication connection between the first electronic device and the second electronic device is disconnected, comparing the target session identifier with a plurality of session identifiers existing in the second electronic device, and if the comparison is successful, sending a second response signal to the first electronic device, so that the first electronic device continues to perform UDP packet transmission with the second electronic device through a target UDP data transmission channel when receiving the second response signal.
In some embodiments, before step 1420, the method further includes negotiating a transmission key corresponding to the target UDP data transmission channel with the first electronic device, and the step 1420 may include receiving, via the target UDP data transmission channel, an encrypted UDP data packet sent by the first electronic device, and decrypting the UDP data packet based on the transmission key.
In some embodiments, negotiating a transmission key corresponding to a target UDP data transmission path with the first electronic device includes negotiating a temporary key with the first electronic device if the UDP data transmission path is first established with the first electronic device, and negotiating a transmission key corresponding to the target UDP data transmission path with the first electronic device based on the temporary key.
It should be noted that, the description of the data transmission method applied to the second electronic device provided in the embodiment of the present application may refer to the related description of the data transmission method applied to the first electronic device provided in each embodiment, and the detailed description is not repeated here.
In the embodiment of the application, the UDP data transmission channels corresponding to the session identifications can be established between different electronic devices, UDP data packet transmission can be realized through the UDP data transmission channels corresponding to the session identifications as long as the session identifications are unchanged, the strong coupling relation between the UDP protocol and the network of the bottom layer can be weakened, and the UDP data transmission channels between the two electronic devices can be still maintained when the network of the bottom layer is changed, so that the stability of data transmission is improved. In addition, different UDP data transmission channels between two electronic devices can correspond to different session identifications, the different UDP data transmission channels cannot be mutually influenced, independent transmission control of each UDP data transmission channel can be realized, and the flexibility and the transmission efficiency of data transmission are improved.
As shown in fig. 15, in one embodiment, a data transmission apparatus 1500 is provided, which may be applied to the first electronic device described above, and the data transmission apparatus 1500 may include a first channel establishment module 1510 and a first transmission module 1520.
A first channel establishing module 1510, configured to establish a target UDP data transmission channel with the second electronic device, where the target UDP data transmission channel corresponds to a target session identifier, and the target session identifier is used to identify the target UDP data transmission channel;
the first transmission module 1520 is configured to perform UDP packet transmission with the second electronic device through the target UDP data transmission channel, where the UDP packet transmitted by the target UDP data transmission channel carries the target session identifier.
In one embodiment, the target session identification is determined based on a target service provided by the target application.
In one embodiment, the target session identification is generated based on an application identification of the target application, a service identification of the target service, and a random number.
In one embodiment, the first channel setup module 1510 includes a first identifier acquisition unit, a first socket creation unit, and a first setup unit.
And the first identifier acquisition unit is used for acquiring the target session identifier.
And the first socket creation unit is used for creating a first UDP socket based on the target session identifier.
The first establishing unit is used for establishing a target UDP data transmission channel with a second UDP socket of the second electronic device through the first UDP socket, and the second UDP socket is created by the second electronic device based on the target session identifier.
In one embodiment, the first establishing unit is further configured to send a first request signal through the first UDP socket, where the first request signal is used to instruct the second electronic device to receive the first request signal through the second UDP socket and feed back the first response signal, receive the first response signal sent by the second electronic device through the first UDP socket, and establish a target UDP data transmission channel between the first UDP socket and the second UDP socket.
In an embodiment, the first identifier obtaining unit is further configured to receive, through a target communication connection with the second electronic device, a target session identifier sent by the second electronic device, where the target session identifier is generated by the second electronic device. Or alternatively
The first identifier obtaining unit is further used for generating a target session identifier.
The data transmission apparatus 1500 further includes a first identification transmission module.
The first identifier sending module is used for sending the generated target session identifier to the second electronic equipment through target communication connection with the second electronic equipment.
In one embodiment, the UDP packet further carries a packet sequence number, where the packet sequence number is used to characterize a transmission sequence corresponding to the UDP packet.
In one embodiment, the data transmission apparatus 1500 further includes a retransmission determination module and an allocation module.
And the retransmission determining module is used for determining the target UDP data packet needing to be retransmitted.
And the distribution module is used for distributing a target packet sequence number for the target UDP data packet, wherein the target packet sequence number is the next packet sequence number of the packet sequence number carried by the last transmitted UDP data packet.
The first transmission module 1520 is further configured to send the target UDP packet carrying the target packet sequence number to the second electronic device via the target UDP data transmission channel.
In one embodiment, the retransmission determining module is further configured to determine that the first UDP packet is a target UDP packet that needs to be retransmitted if an acknowledgement signal sent by the second electronic device is not received within a first duration of sending the first UDP packet, where the acknowledgement signal is used to indicate that the second electronic device receives the first UDP packet.
In one embodiment, the first transmission module 1520 is further configured to send the target number of second UDP data packets to the second electronic device via the target UDP data transmission channel.
And the retransmission determining module is further configured to determine that the target number of second UDP data packets are target UDP data packets that need to be retransmitted if an acknowledgement signal sent by the second electronic device is not received within a first duration after the target number of second UDP data packets are sent, where the acknowledgement signal is used to indicate that the second electronic device receives the target number of second UDP data packets.
In one embodiment, the target number is determined according to a latency requirement corresponding to the target UDP data transmission channel.
In one embodiment, a plurality of UDP data transmission channels established between the first electronic device and the second electronic device share the same physical connection, the plurality of UDP data transmission channels respectively corresponding to different session identifications, and/or,
The target UDP data transmission channel uses a plurality of physical connections to transmit UDP data packets.
In one embodiment, the data transmission device 1500 further includes a broadcast module and a response receiving module.
And the broadcasting module is used for sending a broadcasting signal under the condition that the communication connection between the first electronic equipment and the second electronic equipment is disconnected, wherein the broadcasting signal carries the target session identifier, so that the second electronic equipment feeds back a second response signal under the condition that the communication connection is restored.
And the response receiving module is used for receiving a second response signal sent by the second electronic equipment.
The first transmission module 1520 is further configured to continue UDP packet transmission with the second electronic device via the target UDP data transmission channel.
In one embodiment, the data transmission apparatus 1500 further includes a first key agreement module.
And the first key negotiation module is used for negotiating a transmission key corresponding to the target UDP data transmission channel with the second electronic equipment.
The first transmission module 1520 is further configured to encrypt the UDP packet based on the transmission key, and send the encrypted UDP packet to the second electronic device via the target UDP data transmission channel.
In one embodiment, the first key negotiation module is further configured to negotiate a temporary key with the second electronic device when the UDP data transmission channel is first established with the second electronic device, and negotiate a transmission key corresponding to the target UDP data transmission channel with the second electronic device based on the temporary key.
In one embodiment, the first key negotiation module is further configured to negotiate a transmission key corresponding to the target UDP data transmission channel with the second electronic device based on the stored temporary key if the UDP data transmission channel is not first established with the second electronic device.
In the embodiment of the application, the UDP data transmission channels corresponding to the session identifications can be established between different electronic devices, UDP data packet transmission can be realized through the UDP data transmission channels corresponding to the session identifications as long as the session identifications are unchanged, the strong coupling relation between the UDP protocol and the network of the bottom layer can be weakened, and the UDP data transmission channels between the two electronic devices can be still maintained when the network of the bottom layer is changed, so that the stability of data transmission is improved. In addition, different UDP data transmission channels between two electronic devices can correspond to different session identifications, the different UDP data transmission channels cannot be mutually influenced, independent transmission control of each UDP data transmission channel can be realized, and the flexibility and the transmission efficiency of data transmission are improved.
As shown in fig. 16, in one embodiment, a data transmission apparatus 1600 is provided and can be applied to the second electronic device, where the data transmission apparatus 1600 includes a second channel establishing module 1610 and a second transmission module 1620.
The second channel establishing module 1610 is configured to establish a target UDP data transmission channel with the first electronic device, where the target UDP data transmission channel corresponds to a target session identifier, and the target session identifier is used to identify the target UDP data transmission channel.
The second transmission module 1620 is configured to perform UDP packet transmission with the first electronic device through the target UDP data transmission channel, where the UDP packet transmitted by the target UDP data transmission channel carries the target session identifier.
In one embodiment, the second channel setup module 1610 may include a second identifier acquisition unit, a second socket creation unit, and a second setup unit.
And the second identifier acquisition unit is used for acquiring the target session identifier.
And the second socket creation unit is used for creating a second UDP socket based on the target session identifier.
The second establishing unit is used for establishing a target UDP data transmission channel with a first UDP socket of the first electronic device through a second UDP socket, and the first UDP socket is created by the first electronic device based on the target session identifier.
In one embodiment, the second establishing unit is further configured to receive, through the second UDP socket, a first request signal sent by the first electronic device through the first UDP socket, and send, through the second UDP socket, a first response signal to the first electronic device, so that the first electronic device receives the first response signal through the first UDP socket, and establish a target UDP data transmission channel between the first UDP socket and the second UDP socket.
In an embodiment, the second identifier obtaining unit is further configured to receive, through a target communication connection with the first electronic device, a target session identifier sent by the first electronic device, where the target session identifier is generated by the first electronic device. Or alternatively
The second identifier obtaining unit is further used for generating a target session identifier.
The data transmission device 1600 further includes a second identity transmission module.
And the second identifier sending module is used for sending the generated target session identifier to the first electronic equipment through target communication connection with the first electronic equipment.
In one embodiment, the data transmission device 1600 further includes a upload module.
And the uploading module is used for uploading the UDP data packets with the target number to a target application program corresponding to the UDP data transmission channel under the condition that the UDP data packets with the target number transmitted by the first electronic device are successfully received through the target UDP data transmission channel.
In one embodiment, the data transmission device 1600 further includes an acknowledgement module.
And the confirmation module is used for sending a confirmation signal to the first electronic equipment under the condition that the target number of UDP data packets sent by the first electronic equipment are successfully received through the target UDP data transmission channel, and/or not sending the confirmation signal to the first electronic equipment under the condition that the packet loss exists in the target number of UDP data packets so as to enable the first electronic equipment to resend the target number of UDP data packets.
In one embodiment, the data transmission device 1600 further includes a broadcast receiving module, a comparing module, and a response transmitting module.
The broadcast receiving module is used for receiving a broadcast signal sent by the first electronic equipment, wherein the broadcast signal carries a target session identifier, and the broadcast signal is sent by the first electronic equipment under the condition that communication connection between the first electronic equipment and the second electronic equipment is disconnected.
And the comparison module is used for comparing the target session identifier with a plurality of session identifiers existing in the second electronic equipment.
And the response sending module is used for sending a second response signal to the first electronic equipment if the comparison is successful, so that the first electronic equipment can continue to transmit the UDP data packet with the second electronic equipment through the target UDP data transmission channel under the condition that the first electronic equipment receives the second response signal.
In one embodiment, the data transmission apparatus 1600 further comprises a second key agreement module.
And the second key negotiation module is used for negotiating a transmission key corresponding to the target UDP data transmission channel with the first electronic equipment.
The second transmission module 1620 is further configured to receive, through the target UDP data transmission channel, the encrypted UDP data packet sent by the first electronic device, and decrypt the UDP data packet based on the transmission key.
In one embodiment, the second key negotiation module is further configured to negotiate a temporary key with the first electronic device if the UDP data transmission channel is first established with the first electronic device, and negotiate a transmission key corresponding to the target UDP data transmission channel with the first electronic device based on the temporary key.
In the embodiment of the application, the UDP data transmission channels corresponding to the session identifications can be established between different electronic devices, UDP data packet transmission can be realized through the UDP data transmission channels corresponding to the session identifications as long as the session identifications are unchanged, the strong coupling relation between the UDP protocol and the network of the bottom layer can be weakened, and the UDP data transmission channels between the two electronic devices can be still maintained when the network of the bottom layer is changed, so that the stability of data transmission is improved. In addition, different UDP data transmission channels between two electronic devices can correspond to different session identifications, the different UDP data transmission channels cannot be mutually influenced, independent transmission control of each UDP data transmission channel can be realized, and the flexibility and the transmission efficiency of data transmission are improved.
Fig. 17 is a block diagram of an electronic device in one embodiment. As shown in fig. 17, the electronic device 1700 may include one or more processors 1710, a memory 1720 coupled to the processor 1710, and a transceiver unit, wherein the memory 1720 may store one or more computer programs that, when executed by the one or more processors 1710, may be configured to cause the electronic device 1700 to implement a data transmission method as described in the above embodiments as being applied to a first electronic device.
Processor 1710 may include one or more processing cores. The processor 1710 utilizes various interfaces and lines to connect various portions of the overall electronic device 1700, perform various functions of the electronic device 1700, and process data by executing or executing instructions, programs, code sets, or instruction sets stored in the memory 1720, and invoking data stored in the memory 1720. Alternatively, the processor 1710 can be implemented in hardware in at least one of digital signal Processing (DIGITAL SIGNAL Processing, DSP), field-Programmable gate array (Field-Programmable GATE ARRAY, FPGA), programmable logic array (Programmable Logic Array, PLA). The processor 1710 may integrate one or a combination of several of a central processing unit (Central Processing Unit, CPU), an image processor (Graphics Processing Unit, GPU), and a modem, etc. The CPU mainly processes an operating system, a user interface, an application program and the like, the GPU is used for rendering and drawing display contents, and the modem is used for processing wireless communication. It will be appreciated that the modem may not be integrated into the processor 1710 and may be implemented solely by a single communication chip.
Memory 1720 may include random access Memory (Random Access Memory, RAM) or Read-Only Memory (ROM). Memory 1720 may be used to store instructions, programs, code, sets of codes, or sets of instructions. The memory 1720 may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for implementing at least one function (e.g., a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the various method embodiments described above, and the like. The storage data area may also store data created by the electronic device 1700 in use, and the like.
The transceiver unit may include, but is not limited to, a bluetooth module, a Wi-Fi module, etc., and may be used to provide communication functions.
The embodiment of the application discloses an electronic device, which comprises a memory, a processor and a receiving and transmitting unit, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the earphone device realizes the data transmission method applied to the second electronic device as described in the above embodiments.
The embodiments of the present application disclose a computer readable storage medium storing a computer program, wherein the computer program, when executed by a processor in an electronic device, causes the electronic device to implement a data transmission method applied to a first electronic device as described in the above embodiments.
The embodiments of the present application disclose a computer readable storage medium storing a computer program, wherein the computer program, when executed by a processor in an electronic device, causes the electronic device to implement a data transmission method applied to a second electronic device as described in the above embodiments.
Embodiments of the present application disclose a computer program product comprising a computer program which, when executed by a processor in an electronic device, causes the electronic device to implement a data transmission method as described in the above embodiments as applied to a first electronic device.
Embodiments of the present application disclose a computer program product comprising a computer program which, when executed by a processor in an electronic device, causes the electronic device to implement a data transmission method as described in the above embodiments as applied to a second electronic device.
Those skilled in the art will appreciate that all or part of the processes in the methods of the above embodiments may be implemented by a computer program for instructing relevant hardware, where the program may be stored in a non-volatile computer readable storage medium, and where the program, when executed, may include processes in the embodiments of the methods described above. Wherein the storage medium may be a magnetic disk, an optical disk, a ROM, etc.
Any reference to memory, storage, database, or other medium as used herein may include non-volatile and/or volatile memory. Suitable nonvolatile memory can include ROM, programmable ROM (PROM), erasable PROM (EPROM), electrically Erasable PROM (ELECTRICALLY ERASABLE PROM, EEPROM), or flash memory. Volatile memory can include random access memory (random access memory, RAM), which acts as external cache memory. By way of illustration and not limitation, RAM may take many forms, such as static RAM (STATIC RAM, SRAM), dynamic RAM (Dynamic Random Access Memory, DRAM), synchronous DRAM (SDRAM), double-data-rate SDRAM (Double DATA RATE SDRAM, DDR SDRAM), enhanced SDRAM (Enhanced Synchronous DRAM, ESDRAM), synchronous link DRAM (SYNCHLINK DRAM, SLDRAM), memory bus Direct RAM (Rambus DRAM), and Direct memory bus dynamic RAM (DRDRAM).
It should be appreciated that reference throughout this specification to "one embodiment" or "an embodiment" means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Thus, the appearances of the phrases "in one embodiment" or "in an embodiment" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. Those skilled in the art will also appreciate that the embodiments described in the specification are alternative embodiments and that the acts and modules referred to are not necessarily required for the present application. The term "plurality" in the present application includes "two or more".
In various embodiments of the present application, it should be understood that the sequence numbers of the foregoing processes do not imply that the execution sequences of the processes should be determined by the functions and internal logic of the processes, and should not be construed as limiting the implementation of the embodiments of the present application.
The units described above as separate components may or may not be physically separate, and components shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The technical features of the above-described embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above-described embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing has described in detail a data transmission method, apparatus, electronic device and computer program product according to embodiments of the present application, and specific examples have been applied to illustrate the principles and embodiments of the present application, and the above description of the embodiments is only for aiding in understanding the method and core idea of the present application. Meanwhile, as those skilled in the art will have variations in the specific embodiments and application scope in accordance with the ideas of the present application, the present description should not be construed as limiting the present application in view of the above.