Data transmission method and device, electronic equipment and computer program product
Through the coordinated cooperation between the data sending and receiving end, the server records and forwards the public network address and port information, adds the keep-alive port mechanism, and performs multiple retrys, solving the problem of server load pressure and low NAT penetration success rate, and achieving efficient end-to-end communication.
Patent Information
- Application Number
- CN202510653839.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-20
- Publication Date
- 2025-08-12
AI Technical Summary
In the prior art, the server load pressure is high during data transmission between devices, resulting in long message delay, unable to provide services when the server is overloaded, and the NAT penetration success rate is low, especially in complex NAT types, it is difficult to achieve end-to-end communication.
Through the coordination between the data sending end and the receiving end, the server records and forwards the public network address and port information, adds the keep-alive port mechanism, performs multiple retrys, and uses a random keep-alive port to send data packets when the original port fails, improving the penetration success rate.
It improves data transmission efficiency and success rate, especially under complex NAT types, significantly improves penetration success rate, reduces server load increase, and achieves fast and stable end-to-end communication.
Smart Images

Figure CN120475009A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a data transmission method, a data transmission device, an electronic device, and a computer program product. Background Art
[0002] In the Internet scenario, data transmission between devices is usually based on the client-server model. The two devices usually communicate with each other through the server to forward data. Figure 1 As shown, the client sending data first sends the data to the server. After receiving the data, the server forwards it to the client receiving the data. Various data verifications are performed on the server to ensure the accuracy of the data, and then forwarded, so that safe and reliable data communication can be achieved.
[0003] However, there are some problems with the above data transmission method. For example, when a large amount of data needs to be sent, the server load pressure is very high. Server overload will cause message delays to increase. When overloaded, it will be unable to continue to provide services. Continuing to expand the server cluster will greatly increase bandwidth costs.
[0004] In view of this, there is an urgent need in the art for a data transmission method that can improve data transmission efficiency and success rate.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the Invention
[0006] The purpose of the present disclosure is to provide a data transmission method, a data transmission device, an electronic device and a computer program product, thereby at least to a certain extent improving the data transmission efficiency and success rate.
[0007] According to a first aspect of the present disclosure, a data transmission method is provided, which is applied to a data transmitting end and includes:
[0008] Sending penetration request data to a server, and forwarding the penetration request data to a data receiving end through the server, wherein the penetration request data includes the public network address and sending port of the data sending end;
[0009] Receiving penetration response data of the data receiving end forwarded by the server, wherein the penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end;
[0010] Sending a data packet to the data receiving end according to the public network address of the data receiving end and the receiving port;
[0011] If the data packet fails to be sent, the data packet is sent to the data receiving end according to the public network address of the data receiving end and the keep-alive port.
[0012] In an exemplary embodiment of the present disclosure, the server is configured to record and forward the public network address and port of each client after network address translation; before sending the penetration request data to the server, the method further includes:
[0013] Requesting the server to obtain the public network address and receiving port of the data receiving end;
[0014] Send inquiry request data to the data receiving end according to the public network address and receiving port of the data receiving end.
[0015] In an exemplary embodiment of the present disclosure, the method further includes:
[0016] Set the maximum number of retries for the data sender;
[0017] If the number of times the data packet has been sent is less than or equal to the maximum number of retries, resending the data packet until it is successfully sent;
[0018] If the number of times the data packet is sent is greater than the maximum number of retries, the sending is abandoned.
[0019] According to a second aspect of the present disclosure, a data transmission method is provided, which is applied to a data receiving end and includes:
[0020] Receiving penetration request data from a data sending end forwarded by a server, wherein the penetration request data includes a public network address and a sending port of the data sending end;
[0021] Sending penetration response data to the server, and forwarding the penetration response data to the data sending end through the server, wherein the penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end;
[0022] Receiving, through the receiving port, a data packet sent by the data sending end according to the public network address of the data receiving end and the receiving port;
[0023] If the receiving port fails to receive the data packet, the data packet sent by the data sending end is received through the keep-alive port.
[0024] In an exemplary embodiment of the present disclosure, the method further includes:
[0025] Acquire idle ports of the data receiving end, and determine at least one port from the idle ports as the keep-alive port;
[0026] The keep-alive port is controlled to send a keep-alive data packet to the server according to a preset time interval to complete the keep-alive.
[0027] In an exemplary embodiment of the present disclosure, the server is configured to record and forward the public network address and port of each client after network address translation; after receiving the penetration request data from the data sending end forwarded by the server, the method further includes:
[0028] Send inquiry response data to the data sending end according to the public network address and sending port of the data sending end.
[0029] According to a third aspect of the present disclosure, there is provided a data transmission device, applied to a data sending end, comprising:
[0030] a penetration request sending module, configured to send penetration request data to a server and forward the penetration request data to a data receiving end through the server, wherein the penetration request data includes a public network address and a sending port of the data sending end;
[0031] a penetration response receiving module, configured to receive penetration response data of the data receiving end forwarded by the server, wherein the penetration response data includes the public network address, receiving port and keep-alive port of the data receiving end;
[0032] A receiving port sending module is configured to send a data packet to the data receiving end according to the public network address of the data receiving end and the receiving port;
[0033] The keep-alive port sending module is configured to send a data packet to the data receiving end according to the public network address of the data receiving end and the keep-alive port if the data packet fails to be sent.
[0034] In an exemplary embodiment of the present disclosure, the server is used to record and forward the public network address and port of each client after network address translation; the data transmission device further includes a query request sending module, and the query request sending module includes:
[0035] A public network address acquisition unit is configured to execute a request to the server to acquire the public network address and receiving port of the data receiving end;
[0036] The query request sending unit is configured to send query request data to the data receiving end according to the public network address and receiving port of the data receiving end.
[0037] In an exemplary embodiment of the present disclosure, the data transmission device further includes a data transmission retry module, and the data transmission retry module includes:
[0038] A maximum retry times setting unit is configured to set the maximum retry times of the data sending end;
[0039] a data packet resending unit, configured to resend the data packet until the data packet is successfully sent if the number of times the data packet has been sent is less than or equal to the maximum number of retries;
[0040] The data packet abandoning sending unit is configured to abandon sending if the number of times the data packet has been sent is greater than the maximum number of retries.
[0041] According to a fourth aspect of the present disclosure, there is provided a data transmission device, applied to a data receiving end, comprising:
[0042] a penetration request receiving module configured to receive penetration request data from a data sending end forwarded by a server, wherein the penetration request data includes a public network address and a sending port of the data sending end;
[0043] a penetration response sending module, configured to send penetration response data to the server and forward the penetration response data to the data sending end through the server, wherein the penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end;
[0044] A receiving port receiving module is configured to receive, through the receiving port, a data packet sent by the data sending end according to the public network address of the data receiving end and the receiving port;
[0045] The keep-alive port receiving module is configured to receive the data packet sent by the data sending end through the keep-alive port if the receiving port fails to receive the data packet.
[0046] In an exemplary embodiment of the present disclosure, the data transmission device further includes a port keep-alive module, and the port keep-alive module includes:
[0047] an idle port determining unit, configured to acquire idle ports of the data receiving end, and determine at least one port from the idle ports as the keep-alive port;
[0048] The keep-alive data packet sending unit is configured to control the keep-alive port to send the keep-alive data packet to the server according to a preset time interval to complete the keep-alive operation.
[0049] In an exemplary embodiment of the present disclosure, the server is used to record and forward the public network address and port of each client after network address conversion; the data transmission device also includes an inquiry response sending module, which is configured to execute inquiry response data to the data sending end based on the public network address and sending port of the data sending end.
[0050] According to a fifth aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement any one of the above-mentioned data transmission methods.
[0051] According to a sixth aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any one of the above-mentioned data transmission methods.
[0052] The exemplary embodiments of the present disclosure may have the following beneficial effects:
[0053] In the data transmission method of the example embodiment of the present disclosure, the data sending end sends penetration request data to the server, and the server forwards the penetration request data to the data receiving end; after receiving the penetration request data, the data receiving end sends penetration response data to the server, and the server forwards the penetration response data to the data sending end, wherein the penetration response data includes the public network address, receiving port and keep-alive port of the data receiving end; after receiving the penetration response data, the data sending end sends a data packet to the data receiving end according to the public network address and receiving port of the data receiving end in the penetration response data; if the sending fails, the data packet is resent to the data receiving end according to the public network address and keep-alive port of the data receiving end. The data transmission method in the example implementation mode of the present disclosure, through the cooperation of both ends, keeps a batch of ports alive on the penetrated side, screens out the keep-alive ports that can be used, adds a new available port on the basis of the original port, improves the possibility of the port successfully reaching the other side, and adds a server reply command, writes the keep-alive port that can be used into the signaling, and brings it to the party that actively initiates data transmission through the server, allowing it to initiate the request again, thereby increasing the possibility of successful penetration, improving the penetration success rate in certain special scenarios, and the effect is very significant when the original port cannot be used.
[0054] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] The accompanying drawings are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and those skilled in the art can derive other drawings based on these drawings without inventive effort.
[0056] Figure 1 A schematic diagram showing a data transmission method in the prior art of the present disclosure is shown;
[0057] Figure 2 A schematic diagram showing a data transmission method in a related embodiment of the present disclosure is shown;
[0058] Figure 3 A schematic diagram illustrating a data transmission method in another related embodiment of the present disclosure is shown;
[0059] Figure 4 A schematic flow chart showing a data transmission method applied to a data transmitting end according to an exemplary embodiment of the present disclosure is shown;
[0060] Figure 5 A schematic diagram illustrating a multiple retry mechanism in a specific embodiment of the present disclosure is shown;
[0061] Figure 6 A schematic flow chart showing a data transmission method applied to a data receiving end according to an exemplary embodiment of the present disclosure is shown;
[0062] Figure 7 A schematic diagram showing a flow chart of a port keep-alive method at a data receiving end according to an exemplary embodiment of the present disclosure;
[0063] Figure 8 A schematic diagram illustrating a port keep-alive mechanism in a specific embodiment of the present disclosure is shown;
[0064] Figure 9 A schematic diagram of re-penetration using a keep-alive port in one embodiment of the present disclosure is shown;
[0065] Figure 10 A schematic diagram showing a penetration success indicator in a specific embodiment of the present disclosure is shown;
[0066] Figure 11 A block diagram showing a data transmission device applied to a data transmitting end according to an exemplary embodiment of the present disclosure is shown;
[0067] Figure 12 A block diagram showing a data transmission device applied to a data receiving end according to an exemplary embodiment of the present disclosure is shown;
[0068] Figure 13A schematic structural diagram of a computer system suitable for implementing the electronic device according to the embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0069] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0070] It should be noted that the terms "first," "second," and the like in the specification and claims of the present disclosure and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, such that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein.
[0071] The following example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; rather, these embodiments are provided so that the present disclosure will be more comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or that other methods, components, devices, steps, etc. may be employed. In other cases, well-known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0072] In addition, the accompanying drawings are merely schematic illustrations of the present disclosure and are not necessarily drawn to scale. Identical reference numerals in the figures denote identical or similar parts, and thus repetitive descriptions thereof will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0073] In some related embodiments, two devices can communicate directly without using a server to forward messages, i.e., end-to-end communication. End-to-end communication can provide a fast bandwidth and low latency experience while saving server costs.
[0074] Figure 2A schematic diagram of a data transmission method in a related embodiment of the present disclosure is shown. Two devices obtain the other party's IP address and port through the server. The data sender can then establish a connection with the data receiver, enabling direct communication through data transmission and reception. This technology plays an important role in many practical application scenarios, some of which include: multi-person real-time communication, file sharing, real-time gaming, remote access, and the Internet of Things, enabling a fast, stable, and low-latency experience.
[0075] The ease of end-to-end communication depends on the network environment of the two devices. If both devices are on a public network, they can establish a direct connection and communicate data after knowing the other party's IP address and port. However, due to the lack of IPv4 (Internet Protocol Version 4), it is impossible for every device to have a fixed IP address.
[0076] On this basis, in order to save global address space, NAT (Network Address Translation) can be introduced on routers. Network Address Translation is a technology used in computer networks to convert IP addresses within private networks into a small number of public IP addresses, which can solve the problem of insufficient IPv4 address resources.
[0077] Introducing NAT on the router completes the conversion of the address space, so that when an intranet device under the router accesses the external network, the intranet address of the device will be converted by the router into a specific external network address, and the mapping relationship between the two IP addresses will be recorded in the router's NAT mapping table. If a public IP address is mapped to multiple private IP addresses, the problem of external devices being unable to access the device behind NAT will arise, because NAT cannot determine which private address to access through a public IP address. Therefore, when an external host wants to access an internal host, the destination address is still a specific external network address, but after reaching the exit router, the NAT mapping table is read and converted to an internal network address. The conversion between internal and external network addresses is unique under the router (local area network), which solves the problem of scarce IPv4 addresses, but this also greatly increases the difficulty of communication between devices in different network environments.
[0078] In other related embodiments, in order to solve the end-to-end communication problem in the above-mentioned scenario, both ends generally use the TCP / UDP protocol with the help of a server in a third-party public network environment to perform NAT penetration on both ends. After the penetration is successful, end-to-end communication can be carried out, thereby supporting the needs of real-time communication and distributed systems in the modern Internet. Among them, TCP (Transmission Control Protocol) is a connection-oriented, reliable transport layer protocol that is widely used in the Internet and local area networks. Its main features and functions include: connection-oriented, reliable transmission, flow control, congestion control, etc. It is widely used in data transmission scenarios that require high reliability. UDP (User Datagram Protocol) is a connectionless, simple transport layer protocol that is widely used in network communication scenarios that require fast transmission and low latency. Compared with TCP, UDP provides a lighter-weight transmission method, but lacks certain reliability mechanisms and is widely used in scenarios that require fast transmission and low latency.
[0079] Figure 3 A schematic diagram of a data transmission method in another embodiment of the present disclosure is shown, which is a case where two clients use the UDP protocol to penetrate under different NATs. Figure 3As shown in the figure, the server can be used as a forwarder for penetration information. The server records and forwards the IP addresses and port numbers of client A and client B after NAT mapping, that is, eip:eport. When both clients are located behind NAT devices, any connection request between client A and client B in any direction will be blocked by the other party's NAT device. The general process of NAT penetration can be described as follows: Client A first requests the server, telling the server which device it wants to communicate with. The server then responds. Client A obtains the IP address and port number eipB:eportB of Client B after NAT mapping. It then sends a query request packet (HELLO_REQ) to Client B, creating a hole in NAT A with the direction eipB:eportB. At the same time, it sends a NAT penetration request (SERVER_REQ) to the server. The server forwards Client A's IP address and port number eipA:eportA to Client B. Client B receives the SERVER_RELAY_REQ forwarded by the server. After receiving it, it parses the IP address and port number eipA:eportA in the SERVER_RELAY_REQ and sends a NAT penetration reply command (HELLO_RSP) to eipA:eportA, creating a hole in NAT B with the direction eipA:eportA. After this, packets or connection requests sent by Client A to eipB:eportB will not be discarded. As a result, both Client A and B can receive messages from each other, and end-to-end communication is successful.
[0080] In the above solution, both ends report the external network IP address and port number to the server. When performing NAT penetration, the information of the other end is told to the two clients. Then the two clients send data packets to the other end, completing the penetration and successfully communicating. However, the penetration success rate of the above NAT penetration method is low. If several key data packets are lost, it will directly lead to penetration failure. Especially for two clients with relatively complex NAT types, the penetration success rate will be extremely low after only a few data packet exchanges. Secondly, the penetration success rate is extremely low in some special scenarios, with a success rate of less than 10%, such as the following two scenarios:
[0081] 1. If the port number of the other end after NAT mapping is blocked for some reason and becomes unavailable, the penetration will fail.
[0082] 2. If the two-end NAT type is more complex (such as port restriction cone), NAT has more restrictions on data packets and the penetration success rate will be extremely low.
[0083] Therefore, although the above penetration solution is simple to implement, the penetration success rate is low, the application scenarios are limited, and penetration cannot be completed in complex scenarios.
[0084] Based on the above problems, this exemplary embodiment first provides a data transmission method, which is applied to a data sending end. Figure 4 As shown, the above data transmission method may include the following steps:
[0085] Step S410: Send penetration request data to the server, and forward the penetration request data to the data receiving end through the server. The penetration request data includes the public network address and sending port of the data sending end.
[0086] Step S420: Receive penetration response data from the data receiving end forwarded by the server, where the penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end.
[0087] Step S430: Send a data packet to the data receiving end according to the public network address and receiving port of the data receiving end.
[0088] Step S440: If the data packet fails to be sent, the data packet is sent to the data receiving end according to the public network address and keep-alive port of the data receiving end.
[0089] The data transmission method in the example implementation mode of the present disclosure, through the cooperation of both ends, keeps a batch of ports alive on the penetrated side, screens out the keep-alive ports that can be used, adds a new available port on the basis of the original port, improves the possibility of the port successfully reaching the other side, and adds a server reply command, writes the keep-alive port that can be used into the signaling, and brings it to the party that actively initiates data transmission through the server, allowing it to initiate the request again, thereby increasing the possibility of successful penetration, improving the penetration success rate in certain special scenarios, and the effect is very significant when the original port cannot be used.
[0090] Next, combine Figure 5 The above steps of this exemplary embodiment are described in more detail.
[0091] In step S410, penetration request data is sent to the server, and the penetration request data is forwarded to the data receiving end through the server. The penetration request data includes the public network address and sending port of the data sending end.
[0092] In this example implementation, the server can be used to record and forward the public network address (eip) and port (eport) of each client after network address translation. The client can be divided into a data sender and a data receiver in different data transmission situations.
[0093] In this example implementation, before sending penetration request data to the server, the data sending end may request the server to obtain the public network address and receiving port of the data receiving end, and send query request data to the data receiving end according to the public network address and receiving port of the data receiving end.
[0094] In this example implementation, when both ends penetrate, the data sending end, as the party that actively initiates penetration, will request the server to obtain the public network address and receiving port eip:eport of the data receiving end, and first initiate a query request data HELLO_REQ to the data receiving end, and at the same time send a penetration request SERVER_REQ to the server.
[0095] After receiving the penetration request SERVER_REQ, the server will forward the request to the passive penetration party, that is, the data receiving end. The penetration request received by the other end is the forwarded penetration request SERVER_RELAY_REQ. After receiving it, the address and port in SERVER_RELAY_REQ will be resolved.
[0096] In step S420, the penetration response data of the data receiving end forwarded by the server is received, and the penetration response data includes the public network address, receiving port and keep-alive port of the data receiving end.
[0097] In this example implementation, after receiving a penetration request, the data receiver sends a penetration response to the server, which then forwards it to the data sender. The penetration response includes the data receiver's public network address, receiving port, and keepalive port. A keepalive port is an idle port on the data receiver that is kept alive by a keepalive mechanism. A keepalive mechanism is a technical method used in network communications to maintain an active connection or prevent service termination.
[0098] In this example implementation, the penetration response data SERVER_RSP is the response data sent by the data receiving end to the server after receiving the penetration request SERVER_RELAY_REQ. The server forwards the reply to the data sending end, and the data sending end receives the penetration response data SERVER_RELAY_RSP forwarded by the server.
[0099] After receiving the penetration request SERVER_RELAY_REQ forwarded by the server, the data receiving end puts its own keep-alive port number into SERVER_RSP and sends it to the server, asking the server to forward it to the data sending end.
[0100] In step S430, a data packet is sent to the data receiving end according to the public network address and receiving port of the data receiving end.
[0101] In this example implementation, after receiving the server-forwarded SERVER_RELAY_RSP, the data sending end parses the receiving port number and the keepalive port number contained therein and first sends the data packet to the data receiving end via the data receiving end's public network address and receiving port. If the receiving port can successfully receive the data, the data sending ends.
[0102] In step S440 , if the data packet fails to be sent, the data packet is sent to the data receiving end according to the public network address and keep-alive port of the data receiving end.
[0103] If the packet fails to be sent to the normal receiving port, the packet is sent to the keepalive port of the data receiving end according to the parsed keepalive port number. If the original receiving port is not connected for some reason, the keepalive port is more likely to be connected, thereby improving the connectivity rate of both ends.
[0104] In this example implementation, both ends can add a random port number as a backup keepalive port in addition to the given port. If the first port fails to penetrate, the other random port is used to send the data packet. After receiving the random port number, both ends send the data packet to the other end again through the random port.
[0105] In this example implementation, a multiple retry mechanism can also be used to increase the likelihood of successful penetration. Specifically, a maximum number of retries can be set for the data transmitter. If the number of times a data packet is sent is less than or equal to the maximum number of retries, the data packet is resent until it is successfully sent. If the number of times a data packet is sent is greater than the maximum number of retries, the data packet is abandoned.
[0106] Figure 5 A schematic diagram of a multiple retry mechanism in a specific embodiment of the present disclosure is shown. After receiving the penetration information forwarded by the server, both ends obtain the IP address and port number of the other end and send data packets to the other end. This process may cause packet loss due to network problems, resulting in failure to reach the other end smoothly and leaving a hole in the other end's NAT in this direction. Therefore, after receiving the penetration information forwarded by the server, data packets are sent to the other end at fixed intervals, and a maximum number of retries is set, such as 3 retries. If penetration is successful within 3 retries, retries are stopped. If penetration is still unsuccessful after 3 retries, penetration is abandoned. This increases the possibility of successful penetration while also preventing a large amount of data packet waste.
[0107] For packets sent to the peer, multiple retries are added in addition to the two retries. This multiple retry mechanism avoids penetration failures due to packet loss, improves the possibility of penetration under more complex NAT types, and compensates for the possibility of packet loss.
[0108] If both ends do not sense the success of penetration, they can retry as many times as possible until they sense the success of penetration. They can also adjust the retry interval and speed up the retry frequency, which will further improve the success rate of penetration. However, it will also increase the load on the server. Therefore, it can be selected when the server performance is good.
[0109] This exemplary embodiment first provides a data transmission method, which is applied to a data receiving end. Figure 6 As shown, the above data transmission method may include the following steps:
[0110] Step S610: Receive penetration request data from the data sending end forwarded by the server, where the penetration request data includes the public network address and sending port of the data sending end.
[0111] Step S620: Send penetration response data to the server, and forward the penetration response data to the data sending end through the server. The penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end.
[0112] Step S630: Receive the data packet sent by the data sending end according to the public network address and receiving port of the data receiving end through the receiving port.
[0113] Step S640: If the receiving port fails to receive the data packet, the data packet sent by the data sending end is received through the keep-alive port.
[0114] The data transmission method in the example implementation mode of the present disclosure, through the cooperation of both ends, keeps a batch of ports alive on the penetrated side, screens out the keep-alive ports that can be used, adds a new available port on the basis of the original port, improves the possibility of the port successfully reaching the other side, and adds a server reply command, writes the keep-alive port that can be used into the signaling, and brings it to the party that actively initiates data transmission through the server, allowing it to initiate the request again, thereby increasing the possibility of successful penetration, improving the penetration success rate in certain special scenarios, and the effect is very significant when the original port cannot be used.
[0115] Next, combine Figures 7 and 8 The above steps of this exemplary embodiment are described in more detail.
[0116] In step S610, penetration request data from a data sending end forwarded by a server is received, where the penetration request data includes a public network address and a sending port of the data sending end.
[0117] In this example implementation, the server can be used to record and forward the public network address and port of each client after network address translation. The data sending end will send the penetration request data to the server, which will forward it to the data receiving end.
[0118] In this example implementation, after receiving the penetration request data from the data sending end forwarded by the server, the data receiving end may send query response data to the data sending end according to the public network address and sending port of the data sending end.
[0119] After receiving the penetration request data SERVER_RELAY_REQ forwarded by the server, the data receiving end will parse the public network address and receiving port eip:eport of the data sending end, and then send the query response data HELLO_RSP corresponding to the query request data HELLO_REQ to the data sending end.
[0120] In step S620, penetration response data is sent to the server, and the penetration response data is forwarded to the data sending end through the server. The penetration response data includes the public network address, receiving port and keep-alive port of the data receiving end.
[0121] In this example implementation, after receiving the penetration request, the data receiving end sends a penetration response data to the server, which is forwarded to the data sending end. The penetration response data contains the public network address, receiving port, and keepalive port of the data receiving end.
[0122] In this example implementation, Figure 7 As shown in FIG, the port keep-alive method of the data receiving end may specifically include the following steps:
[0123] Step S710: Obtain idle ports of the data receiving end, and determine at least one port from the idle ports as a keep-alive port.
[0124] When sending and receiving data, both ends mainly use several fixed ports. These ports may be difficult to penetrate for some reasons, so the client can keep multiple unused random idle ports alive through the server.
[0125] Step S720: Control the keep-alive port to send a keep-alive data packet to the server according to a preset time interval to complete the keep-alive.
[0126] The client controls these idle ports to send data packets to the server according to the preset time interval. After receiving the data, the server sends the data to the client's IP and port to complete the keep-alive operation, thereby ensuring the availability of the external network port.
[0127] Figure 8A schematic diagram of the port keepalive mechanism in a specific embodiment of the present disclosure is shown. Assuming that clients A and B use port 1 and port 3, respectively, as the primary ports for normal data transmission and reception, the server can use idle ports 2 and 4 for keepalive. Under normal circumstances, several or even dozens of ports can be selected for keepalive. Both ends use a random port keepalive mechanism to ensure port availability, preventing the failure of packet reception due to random return ports, which can lead to penetration failure.
[0128] When keeping random ports alive, in order to avoid sending too much signaling, you do not need to keep many ports alive. Instead, you can choose one or several infrequently used ports to keep alive, and then periodically change the keep alive ports to achieve the same purpose.
[0129] In step S630, a data packet sent by the data sending end according to the public network address and the receiving port of the data receiving end is received through the receiving port.
[0130] In this example implementation, after receiving the server-forwarded SERVER_RELAY_RSP, the data sending end parses the receiving port number and the keepalive port number contained therein and first sends the data packet to the data receiving end via the data receiving end's public network address and receiving port. If the receiving port can successfully receive the data, the data sending ends.
[0131] In step S640, if the receiving port fails to receive the data packet, the data packet sent by the data sending end is received through the keep-alive port.
[0132] In this example implementation, if the normal receiving port fails to receive data, the data packet sent by the data sending end is received through the keep-alive port. If the original receiving port is not connected for some reason, the keep-alive port is likely to be connected, thereby improving the dual-end connectivity rate.
[0133] Figure 9 This flowchart shows a method for re-penetrating using a keepalive port in a specific embodiment of the present disclosure. This flowchart illustrates the steps described above in this exemplary embodiment, taking client A as the active penetrater and client B as the passive penetrater and keepalive port. The specific steps of this flowchart are as follows:
[0134] Step S910 . Add SERVER_RSP and SERVER_RELAY_RSP, which are respectively when client B receives SERVER_RELAY_REQ and sends a reply SERVER_RSP to the server, and when the server forwards the reply to client A, client A receives SERVER_RELAY_RSP.
[0135] Step S920. After receiving the penetration request SERVER_RELAY_REQ forwarded by the server, client B puts its own keep-alive port number eport4 into SERVER_RSP and sends it to the server, asking the server to forward it to client A.
[0136] Step S930: After receiving SERVER_RELAY_RSP, client A parses the packet to obtain the port number eport4.
[0137] Step S940: Then client A sends a data packet to eport 4 of client B. If eport 3 is blocked for some reason, eport 4 will most likely be connected, thereby improving the connectivity rate of both ends.
[0138] Figure 10 A schematic diagram of a penetration success indicator in a specific embodiment of the present disclosure is shown. If a given evaluation indicator, the penetration success rate, is equal to the number of successful penetrations divided by the number of penetrations, then after implementing the above technical solution, a penetration method that adds multiple retries and uses a random port for re-penetration can effectively improve the dual-end penetration rate compared to the traditional penetration method. While ensuring that the server load does not increase significantly, the use of a random port that is kept alive for re-penetration ensures the availability of the other end, especially in scenarios where the original port is blocked and penetration is impossible, enabling successful connection and data download.
[0139] After implementing the above solution and deploying it on the device, the relevant indicators are plotted as follows: Figure 10 As shown in the figure, 17:52 is the time of change. Before using the traditional penetration method, it can be seen that the number of successful penetrations was basically 0, and the penetration success rate was only about 40%. After changing to multiple retries and using random ports for penetration, the number of successful penetrations instantly increased to nearly 1K, and the penetration success rate quickly increased from 40% to 70%. This shows that this solution greatly improves the penetration success rate, and more devices can be successfully connected.
[0140] In this example implementation, the protocol can also be replaced with TCP protocol for penetration. The main difference between it and UDP penetration is that TCP is connection-oriented. The TCP socket must use the bind call to bind to a host port number. After the connection is established, it cannot communicate to an unconnected address, and the passively listening socket can no longer actively send messages to a certain address. It must use an active connection to create a connection to send data packets. The process is more complicated than UDP.
[0141] It should be noted that although the steps of the method of the present disclosure are described in a specific order in the drawings, this does not require or imply that the steps must be performed in this specific order, or that all steps must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0142] Furthermore, the present disclosure also provides a data transmission device, which is applied to a data sending end. Figure 11 As shown, the data transmission device may include a penetration request sending module 1110 , a penetration response receiving module 1120 , a receiving port sending module 1130 , and a keep-alive port sending module 1140 .
[0143] in:
[0144] The penetration request sending module 1110 is configured to send penetration request data to the server and forward the penetration request data to the data receiving end through the server. The penetration request data includes the public network address and sending port of the data sending end.
[0145] The penetration response receiving module 1120 is configured to receive penetration response data from the data receiving end forwarded by the server, wherein the penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end;
[0146] The receiving port sending module 1130 is configured to send a data packet to the data receiving end according to the public network address and receiving port of the data receiving end;
[0147] The keep-alive port sending module 1140 is configured to send a data packet to the data receiving end according to the public network address and keep-alive port of the data receiving end if the data packet sending fails.
[0148] In some exemplary embodiments of the present disclosure, the server is used to record and forward the public network address and port of each client after network address translation; the data transmission device provided by the present disclosure may also include a query request sending module, which may include a public network address acquisition unit and a query request sending unit.
[0149] The public network address acquisition unit is configured to execute a request to the server to acquire the public network address and receiving port of the data receiving end;
[0150] The query request sending unit is configured to send query request data to the data receiving end according to the public network address and receiving port of the data receiving end.
[0151] In some exemplary embodiments of the present disclosure, a data transmission device provided by the present disclosure may further include a data transmission retry module, which may include a maximum retry count setting unit, a data packet retransmission unit, and a data packet abandonment transmission unit.
[0152] A maximum retry times setting unit is configured to set a maximum retry times of a data sending end;
[0153] a data packet resending unit, configured to resend the data packet until the data packet is successfully sent if the number of times the data packet has been sent is less than or equal to the maximum number of retries;
[0154] The data packet abandoning sending unit is configured to abandon sending if the number of times the data packet has been sent is greater than the maximum number of retries.
[0155] Furthermore, the present disclosure also provides a data transmission device, which is applied to a data receiving end. Figure 12 As shown, the data transmission device may include a penetration request receiving module 1210 , a penetration response sending module 1220 , a receiving port receiving module 1230 , and a keep-alive port receiving module 1240 .
[0156] in:
[0157] The penetration request receiving module 1210 is configured to receive penetration request data from the data sending end forwarded by the server, wherein the penetration request data includes the public network address and sending port of the data sending end;
[0158] The penetration response sending module 1220 is configured to send penetration response data to the server and forward the penetration response data to the data sending end through the server. The penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end.
[0159] The receiving port receiving module 1230 is configured to receive, through the receiving port, a data packet sent by the data sending end according to the public network address and the receiving port of the data receiving end;
[0160] The keep-alive port receiving module 1240 is configured to receive a data packet sent by the data sending end through the keep-alive port if the receiving port fails to receive the data packet.
[0161] In some exemplary embodiments of the present disclosure, the data transmission device further includes a port keep-alive module, which may include an idle port determination unit and a keep-alive data packet sending unit.
[0162] an idle port determining unit, configured to acquire idle ports of the data receiving end and determine at least one port from the idle ports as a keep-alive port;
[0163] The keep-alive data packet sending unit is configured to control the keep-alive port to send the keep-alive data packet to the server according to a preset time interval to complete the keep-alive operation.
[0164] In some exemplary embodiments of the present disclosure, the server is used to record and forward the public network address and port of each client after network address translation; a data transmission device provided by the present disclosure may also include an inquiry response sending module, which is configured to execute inquiry response data to the data sending end based on the public network address and sending port of the data sending end.
[0165] The specific details of each module / unit in the above-mentioned data transmission device have been described in detail in the corresponding method embodiment part and will not be repeated here.
[0166] Figure 13 A schematic diagram of the structure of a computer system suitable for implementing an electronic device according to an embodiment of the present disclosure is shown.
[0167] It should be noted that Figure 13 The computer system 1300 of the electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present disclosure.
[0168] like Figure 13 As shown, computer system 1300 includes a central processing unit (CPU) 1301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1302 or a program loaded from a storage unit 1308 into a random access memory (RAM) 1303. Various programs and data required for system operation are also stored in RAM 1303. CPU 1301, ROM 1302, and RAM 1303 are connected to each other via a bus 1304. An input / output (I / O) interface 1305 is also connected to bus 1304.
[0169] The following components are connected to the I / O interface 1305: an input section 1306 including a keyboard, a mouse, and the like; an output section 1307 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 1308 including a hard disk; and a communication section 1309 including a network interface card such as a LAN card or a modem. The communication section 1309 performs communication processing via a network such as the Internet. A drive 1310 is also connected to the I / O interface 1305 as needed. Removable media 1311, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1310 as needed, so that computer programs read therefrom can be installed into the storage section 1308 as needed.
[0170] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1309, and / or installed from a removable medium 1311. When the computer program is executed by the central processing unit (CPU) 1301, various functions defined in the system of the present disclosure are performed.
[0171] The exemplary embodiments of the present disclosure further provide a computer program product, which includes a computer program, and when the computer program is executed by a processor, implements the above-mentioned data transmission method.
[0172] In one embodiment, a computer program product may be a tangible product containing a computer program, such as a computer-readable storage medium storing the computer program. The computer-readable storage medium may be a storage medium based on electrical, magnetic, optical, electromagnetic, infrared, or other signals, including but not limited to random access memory (RAM), read-only memory (ROM), magnetic tape, floppy disk, flash memory (Flash), mechanical hard disk drive (HDD), solid-state drive (SSD), and the like. Exemplarily, the computer program product may be implemented as a non-volatile storage medium storing the computer program, such as a read-only memory, NAND flash memory, and the like.
[0173] In one embodiment, the computer program product may be an intangible product containing a computer program. For example, the computer program product may be implemented as a virtual digital product, such as a digital file such as an executable file or installation package storing the computer program.
[0174] The code of the computer program can be written in one or more programming languages. Programming languages include C, Java, C++, etc. The program code can be executed entirely on the user computing device, partially on the user computing device, or as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device via any type of network, such as a local area network (LAN), a wide area network (WAN), etc., or can be connected to an external computing device (e.g., via an Internet connection provided by a carrier).
[0175] Computer programs can be carried or transmitted via electrical, magnetic, optical, electromagnetic, infrared, or other signals. Electronic devices can convert signals carrying computer programs into digital signals to run the computer programs. When a computer program is run on an electronic device, its code causes the electronic device to execute (more specifically, the processor of the electronic device to execute) the method steps of various exemplary embodiments of the present disclosure, such as the data transmission method described above.
[0176] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0177] It should be noted that although several modules of the device for action execution are mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules described above can be embodied in one module. Conversely, the features and functions of one module described above can be further divided into multiple modules to be embodied.
[0178] Other embodiments of the present disclosure will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein.
[0179] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data transmission method, applied to a data sending end, characterized in that: include: Sending penetration request data to a server, and forwarding the penetration request data to a data receiving end through the server, wherein the penetration request data includes the public network address and sending port of the data sending end; Receiving penetration response data of the data receiving end forwarded by the server, wherein the penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end; Sending a data packet to the data receiving end according to the public network address of the data receiving end and the receiving port; If the data packet fails to be sent, the data packet is sent to the data receiving end according to the public network address of the data receiving end and the keep-alive port.
2. The data transmission method according to claim 1, wherein: The server is used to record and forward the public network address and port of each client after network address translation; Before sending the penetration request data to the server, the method further includes: Requesting the server to obtain the public network address and receiving port of the data receiving end; Send inquiry request data to the data receiving end according to the public network address and receiving port of the data receiving end.
3. The data transmission method according to claim 1, wherein: The method further comprises: Set the maximum number of retries for the data sender; If the number of times the data packet has been sent is less than or equal to the maximum number of retries, resending the data packet until it is successfully sent; If the number of times the data packet is sent is greater than the maximum number of retries, the sending is abandoned.
4. A data transmission method, applied to a data receiving end, characterized in that: include: Receiving penetration request data from a data sending end forwarded by a server, wherein the penetration request data includes a public network address and a sending port of the data sending end; Sending penetration response data to the server, and forwarding the penetration response data to the data sending end through the server, wherein the penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end; Receiving, through the receiving port, a data packet sent by the data sending end according to the public network address of the data receiving end and the receiving port; If the receiving port fails to receive the data packet, the data packet sent by the data sending end is received through the keep-alive port.
5. The data transmission method according to claim 4, characterized in that: The method further comprises: Acquire idle ports of the data receiving end, and determine at least one port from the idle ports as the keep-alive port; The keep-alive port is controlled to send a keep-alive data packet to the server according to a preset time interval to complete the keep-alive.
6. The data transmission method according to claim 4, characterized in that The server is used to record and forward the public network address and port of each client after network address translation; After receiving the penetration request data from the data sending end forwarded by the server, the method further includes: Send inquiry response data to the data sending end according to the public network address and sending port of the data sending end.
7. A data transmission device, applied to a data sending end, characterized in that: include: a penetration request sending module, configured to send penetration request data to a server and forward the penetration request data to a data receiving end through the server, wherein the penetration request data includes a public network address and a sending port of the data sending end; a penetration response receiving module, configured to receive penetration response data of the data receiving end forwarded by the server, wherein the penetration response data includes the public network address, receiving port and keep-alive port of the data receiving end; A receiving port sending module is configured to send a data packet to the data receiving end according to the public network address of the data receiving end and the receiving port; The keep-alive port sending module is configured to send a data packet to the data receiving end according to the public network address of the data receiving end and the keep-alive port if the data packet fails to be sent.
8. A data transmission device, applied to a data receiving end, characterized in that: include: a penetration request receiving module configured to receive penetration request data from a data sending end forwarded by a server, wherein the penetration request data includes a public network address and a sending port of the data sending end; a penetration response sending module, configured to send penetration response data to the server and forward the penetration response data to the data sending end through the server, wherein the penetration response data includes the public network address, receiving port, and keep-alive port of the data receiving end; A receiving port receiving module is configured to receive, through the receiving port, a data packet sent by the data sending end according to the public network address of the data receiving end and the receiving port; The keep-alive port receiving module is configured to receive the data packet sent by the data sending end through the keep-alive port if the receiving port fails to receive the data packet.
9. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the data transmission method according to any one of claims 1 to 6.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the data transmission method according to any one of claims 1 to 6 is implemented.