Communication methods, devices, equipment, and storage media based on the UDP protocol
By using a UDP-based communication method and exchanging address information between the detection server and the signaling server, the problem of low communication efficiency in client/server or peer-to-peer networks is solved, and fast multi-channel connections are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-22
- Publication Date
- 2026-04-03
AI Technical Summary
In client/server or peer-to-peer network modes, when multiple ports communicate simultaneously, connection establishment becomes difficult and inefficient due to network environment uncertainties.
The communication method based on the UDP protocol is adopted. The device address information is obtained by detecting the server, and the signaling server is used to realize the exchange of address information and the establishment of network address list, so as to quickly establish multiple communication channels.
It enables the rapid establishment of multiple communication channels between the two communicating parties, reducing connection establishment time and improving communication efficiency.
Smart Images

Figure CN116546077B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of network communication technology, and in particular relates to a communication method, apparatus, device and storage medium based on the UDP protocol. Background Technology
[0002] Computer network communication plays an important role in people's daily lives, and various network software cannot function without network communication technology.
[0003] Common application systems use client / server or peer-to-peer (P2P) network modes. However, when multiple ports in these two modes communicate simultaneously, there are many uncertainties due to the complex network environment. As a result, it is necessary to constantly try to establish a connection, which leads to long communication channel waiting times and low efficiency. Summary of the Invention
[0004] This application aims to at least partially address one of the technical problems in the related art. Therefore, one objective of this application is to provide a communication method, apparatus, device, and storage medium based on the UDP protocol.
[0005] To address the aforementioned technical problems, embodiments of this application provide the following technical solutions:
[0006] A communication method based on the UDP protocol, comprising:
[0007] Based on the UDP protocol, the first device receives the first address information fed back by the detection server; at the same time, the second device receives the second address information fed back by the detection server.
[0008] The first device sends the first address information and the first local address information to the second device based on the signaling server, and the second device obtains a first network address list; the second device sends the second address information and the second local address information to the first device based on the signaling server, and the first device obtains a second network address list;
[0009] Based on the first network address list and the second network address list, a first communication channel is established between the first device and the second device;
[0010] After establishing the first communication channel between the first device and the second device, multiple communication channels are established between the first device and the second device based on the communication network address corresponding to the first communication channel.
[0011] Optionally, the first address information includes the IP address and the first port of the first device; the first local address includes the IP address and the first port of the first device when communicating with the detection server;
[0012] The second address information includes the IP address of the second device and the first port; the second local address information includes the IP address of the second device and the first port when communicating with the detection server.
[0013] Optionally, the communication network address includes:
[0014] The first sub-communication network address of the first device corresponding to the first communication channel and the second sub-communication network address of the second device corresponding to the first communication channel;
[0015] The first sub-communication network address of the first device includes: the IP address of the second device or the corresponding IP address of the NAT device;
[0016] The second sub-communication network address of the second device corresponding to the first communication channel includes: the IP address of the first device or the IP address of the corresponding NAT device.
[0017] Optionally, the first device sends the first address information and the first local address information to the second device based on the signaling server, and the second device obtains a first network address list; the second device sends the second address information and the second local address information to the first device based on the signaling server, and the first device obtains a second network address list, including:
[0018] The first device compares the first address information with the first local address information. If the first address information and the first local address information are consistent, the first device retains either the first address information or the first local address information to obtain first retained address information, and sends the first retained address information to the second device, which then obtains the first network address list. Alternatively, if the first address information and the first local address information are inconsistent, the first device retains both the first address information and the first local address information to obtain first retained address information, and sends the first retained address information to the second device, which then obtains the first network address list.
[0019] The second device compares the second address information with the second local address information. If the second address information matches the second local address information, the second device retains either the second address information or the second local address information to obtain second retained address information, and sends the second retained address information to the first device, so that the first device obtains the second network address list. Alternatively, if the second address information does not match the second local address information, the second device retains both the second address information and the second local address information to obtain second retained address information, and sends the second retained address information to the first device, so that the first device obtains the second network address list.
[0020] Optionally, the communication network address includes any one of the following:
[0021] The IP address of the first device and the IP address of the second device; or
[0022] The IP address of the first device, the IP address of the second device, the IP address of the NAT device, and the port.
[0023] Optionally, after establishing the first communication channel between the first device and the second device, and then establishing multiple communication channels between the first device and the second device based on the communication network address corresponding to the first communication channel, the following steps are included:
[0024] When a second communication channel needs to be established, the first device and the second device respectively obtain the communication network address of the first communication channel;
[0025] The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; the second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address.
[0026] The first device receives the port address information of the second port of the first device fed back by the detection server through the second port of the first device; at the same time, the second device receives the port address information of the second port of the second device fed back by the detection server through the second port of the second device.
[0027] The first device determines the port address information of the second port of the second device based on the first valid IP address; the second device determines the port address information of the second port of the first device based on the second valid IP address.
[0028] Based on the port address information of the second port of the first device and the port address information of the second port of the second device, a second communication channel is established between the first device and the second device.
[0029] Optionally, after establishing the first communication channel between the first device and the second device, establishing multiple communication channels between the first device and the second device based on the first network address and the second network address further includes:
[0030] When it is necessary to establish the Nth communication channel, the first device and the second device respectively obtain the communication network address of the first communication channel; where N > 2 and N is an integer;
[0031] The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; the second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address.
[0032] The first device receives the port address information of the Nth port of the first device fed back by the detection server through the Nth port of the first device; at the same time, the second device receives the port address information of the Nth port of the second device fed back by the detection server through the Nth port of the second device.
[0033] The first device determines the port address information of the Nth port of the second device based on the first valid IP address; the second device determines the port address information of the Nth port of the first device based on the second valid IP address.
[0034] Based on the port address information of the Nth port of the first device and the port address information of the Nth port of the second device, the Nth communication channel is established between the first device and the second device.
[0035] Embodiments of this application also provide a communication device based on the UDP protocol, comprising:
[0036] The receiving module is used to receive first address information fed back by the detection server via the UDP protocol, and simultaneously, the second device receives second address information fed back by the detection server.
[0037] The switching module is used for the first device to send the first address information and the first local address information to the second device based on the signaling server, and the second device to obtain a first network address list; the second device to send the second address information and the second local address information to the first device based on the signaling server, and the first device to obtain a second network address list;
[0038] The determining module is used to establish a first communication channel between the first device and the second device based on the first network address list and the second network address list;
[0039] The module is configured to establish multiple communication channels between the first device and the second device after establishing the first communication channel between the first device and the second device, based on the communication network address corresponding to the first communication channel.
[0040] Embodiments of this application also provide an electronic device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the method described above.
[0041] Embodiments of this application also provide a computer-readable storage medium, the computer-readable storage medium including a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the method described above.
[0042] The embodiments of this application have the following technical effects:
[0043] The above-described technical solution of this application is based on the UDP protocol. The first device receives the first address information fed back by the detection server; simultaneously, the second device receives the second address information fed back by the detection server; the second device and the second device exchange network addresses based on the signaling server, and successfully establish a first communication channel between the first device and the second device; after establishing the first communication channel between the first device and the second device, multiple communication channels are established between the first device and the second device based on the first network address list and the second network address list, which can realize the rapid establishment of multiple communication channels between the two parties, with short communication channel establishment time and high efficiency.
[0044] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0045] Figure 1 This is a flowchart illustrating a communication method based on the UDP protocol provided in an embodiment of this application;
[0046] Figure 2 This is a schematic diagram of a communication device based on the UDP protocol provided in an embodiment of this application. Detailed Implementation
[0047] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.
[0048] To facilitate understanding of the embodiments by those skilled in the art, some terms are explained below:
[0049] (1)UDP: User Datagram Protocol.
[0050] (2) IP: Internet Protocol.
[0051] (3) NAT device: Network Address Translation.
[0052] (4) STUN: Session Traversal Utilities for NAT, a NAT session traversal application.
[0053] (5) WebSocket: A protocol for full-duplex communication.
[0054] like Figure 1 As shown, a communication method based on the UDP protocol includes:
[0055] Step S11: Based on the UDP protocol, the first device receives the first address information fed back by the detection server; at the same time, the second device receives the second address information fed back by the detection server.
[0056] In the embodiments of this application, the detection server can be deployed in advance; for example, it can be implemented based on the STUN service; both the first device and the second device are communicatively connected to the detection server.
[0057] Furthermore, the detection server reads the detected data based on the UDP service and obtains the source (first device or second device) IP address and source port (first port, second port, ... or Nth port) included in the data packet; for example, the detection server can parse the first data packet detected to obtain the first address information of the first device and feed back the parsed first address information to the first device; at the same time, the detection server can parse the second data packet detected to obtain the second address information of the second device and feed back the parsed second address information to the second device.
[0058] In an optional embodiment of this application, the first address information includes the IP address and the first port of the first device; the first local address includes the IP address and the first port of the first device when communicating with the detection server.
[0059] The second address information includes the IP address of the second device and the first port; the second local address information includes the IP address of the second device and the first port when communicating with the detection server.
[0060] In an optional embodiment of this application, when the first device and the detection server are not on the same local area network, the first address information includes the IP address of the NAT device and the port of the NAT device;
[0061] When the second device and the detection server are not on the same local area network, the second address information includes the IP address of the NAT device and the port of the NAT device.
[0062] In an embodiment of this application, when the detection server and the first device are not on the same local area network, the detection server cannot obtain the IP address and the first port of the first device. When the detection server is performing detection, it can obtain the IP address and port of the NAT device and feed back the IP address and port of the NAT device to the first device.
[0063] When the detection server and the second device are not on the same local area network, the detection server cannot obtain the IP address and port of the second device. When the detection server is performing the detection, it can obtain the IP address and port of the NAT device and send the IP address and port of the NAT device back to the second device.
[0064] Step S12: The first device sends the first address information and the first local address information to the second device based on the signaling server, and the second device obtains the first network address list; the second device sends the second address information and the second local address information to the first device based on the signaling server, and the first device obtains the second network address list;
[0065] In an optional embodiment of this application, the first device sends the first address information and the first local address information to the second device based on a signaling server, and the second device obtains a first network address list; the second device sends the second address information and the second local address information to the first device based on the signaling server, and the first device obtains a second network address list, including:
[0066] The first device compares the first address information with the first local address information. If the first address information and the first local address information are consistent, the first device retains either the first address information or the first local address information to obtain first retained address information, and sends the first retained address information to the second device, which then obtains the first network address list. Alternatively, if the first address information and the first local address information are inconsistent, the first device retains both the first address information and the first local address information to obtain first retained address information, and sends the first retained address information to the second device, which then obtains the first network address list.
[0067] The second device compares the second address information with the second local address information. If the second address information matches the second local address information, the second device retains either the second address information or the second local address information to obtain second retained address information, and sends the second retained address information to the first device, so that the first device obtains the second network address list. Alternatively, if the second address information does not match the second local address information, the second device retains both the second address information and the second local address information to obtain second retained address information, and sends the second retained address information to the first device, so that the first device obtains the second network address list.
[0068] In embodiments of this application, both the first device and the second device are communicatively connected to a signaling server.
[0069] In an optional embodiment of this application, the signaling server can be implemented based on a WebSocket server. Since the first device and the second device cannot communicate directly before the first communication channel is established, the signaling server is used to forward data between the first device and the second device, enabling the exchange of address information between the first device and the second device, thereby enabling the second device to obtain the first network address list and the first device to obtain the second network address list.
[0070] In an optional embodiment of this application, when both the first device and the second device are on the same local area network as the detection server:
[0071] The first device compares the first address information with the first local address information. If the first address information and the first local address information are consistent, the first device retains either the first address information or the first local address information to obtain the first retained address information. The first retained address information is then sent to the second device, and the second device obtains the first network address list.
[0072] The second device compares the second address information with the second local address information. If the second address information matches the second local address information, the second device retains either the second address information or the second local address information to obtain the second reserved address information. The second reserved address information is then sent to the first device, and the first device obtains the second network address list.
[0073] In an optional embodiment of this application, when neither the first device nor the second device is on the same local area network as the detection server:
[0074] The first device compares the first address information with the first local address information. If the first address information and the first local address information are inconsistent, the first device retains the first address information and the first local address information to obtain the first retained address information, and sends the first retained address information to the second device. The second device then obtains the first network address list.
[0075] The second device compares the second address information with the second local address information, then retains the second address information and the second local address information to obtain the second reserved address information, and sends the second reserved address information to the first device, so that the first device obtains the second network address list.
[0076] In the embodiments of this application, when a first reserved address or a second reserved address is determined, the first reserved address and the second reserved address are encapsulated based on the agreed protocol between the first device and the second device, and then address exchange is implemented based on the signaling server;
[0077] Furthermore, taking the first device as an example, when the first device and the detection server are on the same local area network, the first device needs to perform deduplication before determining the first reserved address. This is because the detection server detects the IP address and port of the first device. Therefore, when the first device compares the IP address and port in the first address information returned by the detection server with the IP address and port in the first local information of the first device, there will be duplicates. Thus, deduplication is required before obtaining the first reserved address.
[0078] When the first device and the detection server are not on the same local area network, the first device does not need to perform deduplication before determining the first reserved address. This is because the detection server detects the IP address and port of the NAT device. Therefore, when the first device compares the IP address and port in the first address information returned by the detection server with the IP address and port in the first local information of the first device, there will be no duplicates. Thus, deduplication is not required, and the first reserved address is obtained.
[0079] Step S13: Based on the first network address list and the second network address list, establish a first communication channel between the first device and the second device;
[0080] In an optional embodiment of this application, the first device obtains the IP address and first port of the second device from the second network address list; simultaneously, the second device obtains the IP address and first port of the first device from the first network address list; and establishes a first communication channel between the first port of the first device and the second port of the second device based on the IP address of the first device and the IP address of the second device.
[0081] Step S14: After establishing the first communication channel between the first device and the second device, establish multiple communication channels between the first device and the second device based on the communication network address corresponding to the first communication channel.
[0082] In an optional embodiment of this application, the communication network address includes:
[0083] The first sub-communication network address of the first device corresponding to the first communication channel and the second sub-communication network address of the second device corresponding to the first communication channel;
[0084] The first sub-communication network address of the first device includes: the IP address of the second device or the corresponding IP address of the NAT device;
[0085] The second sub-communication network address of the second device corresponding to the first communication channel includes: the IP address of the first device or the IP address of the corresponding NAT device.
[0086] In an optional embodiment of this application, after establishing the first communication channel between the first device and the second device, and then establishing multiple communication channels between the first device and the second device based on the communication network address corresponding to the first communication channel, the following steps are included:
[0087] When a second communication channel needs to be established, the first device and the second device respectively obtain the communication network address of the first communication channel;
[0088] The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; the second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address.
[0089] The first device receives the port address information of the second port of the first device fed back by the detection server through the second port of the first device; at the same time, the second device receives the port address information of the second port of the second device fed back by the detection server through the second port of the second device.
[0090] The first device determines the port address information of the second port of the second device based on the first valid IP address; the second device determines the port address information of the second port of the first device based on the second valid IP address.
[0091] Based on the port address information of the second port of the first device and the port address information of the second port of the second device, a second communication channel is established between the first device and the second device.
[0092] In an optional embodiment of this application, after establishing the first communication channel between the first device and the second device, establishing multiple communication channels between the first device and the second device based on the first network address and the second network address further includes:
[0093] When it is necessary to establish the Nth communication channel, the first device and the second device respectively obtain the communication network address of the first communication channel; where N > 2 and N is an integer;
[0094] The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; the second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address.
[0095] The first device receives the port address information of the Nth port of the first device fed back by the detection server through the Nth port of the first device; at the same time, the second device receives the port address information of the Nth port of the second device fed back by the detection server through the Nth port of the second device.
[0096] The first device determines the port address information of the Nth port of the second device based on the first valid IP address; the second device determines the port address information of the Nth port of the first device based on the second valid IP address.
[0097] Based on the port address information of the Nth port of the first device and the port address information of the Nth port of the second device, the Nth communication channel is established between the first device and the second device.
[0098] In the embodiments of this application, when N communication channels need to be established between the first device and the second device for data transmission, when N > 2, each time a new Nth communication channel is constructed, it is not necessary to attempt to establish a connection between the first device and the second device. Based on the communication network address of the first communication channel obtained previously, the IP addresses of the first device and the second device that have successfully established a connection can be filtered out. The IP address of the second device is the first valid IP address, and the IP address of the first device is the second valid IP address. Thus, it can be determined that the first device and the second device have successfully established a connection, and the Nth communication channel is established between the Nth port of the first device and the Nth port of the second device based on the IP addresses of the first device and the second device that have been determined to be able to connect successfully.
[0099] In an optional embodiment of this application, when it is necessary to establish at least one communication channel between the first device and the Mth device, the above steps can be repeated; wherein, M>2, and M is an integer.
[0100] In the embodiments of this application, based on the UDP protocol, the first device receives the first address information fed back by the detection server; simultaneously, the second device receives the second address information fed back by the detection server; the second device and the second device exchange network addresses based on the signaling server, and successfully establish a first communication channel between the first device and the second device; after establishing the first communication channel between the first device and the second device, multiple communication channels are established between the first device and the second device based on the first network address and the second network address, which can realize the rapid establishment of multiple communication channels between the two communicating parties, with short communication channel establishment time and high efficiency.
[0101] Embodiments of this application also provide a communication device 20 based on the UDP protocol, comprising:
[0102] The receiving module 21 is used to receive first address information fed back by the detection server by the first device based on the UDP protocol; at the same time, the second device receives second address information fed back by the detection server.
[0103] The switching module 22 is used for the first device to send the first address information and the first local address information to the second device based on the signaling server, and the second device to obtain a first network address list; the second device to send the second address information and the second local address information to the first device based on the signaling server, and the first device to obtain a second network address list;
[0104] The determining module 23 is used to establish a first communication channel between the first device and the second device based on the first network address list and the second network address list;
[0105] The module 24 is used to establish multiple communication channels between the first device and the second device after establishing the first communication channel between the first device and the second device, based on the communication network address corresponding to the first communication channel.
[0106] Optionally, the first address information includes the IP address and the first port of the first device; the first local address includes the IP address and the first port of the first device when communicating with the detection server;
[0107] The second address information includes the IP address of the second device and the first port; the second local address information includes the IP address of the second device and the first port when communicating with the detection server.
[0108] Optionally, when the first device and the detection server are not on the same local area network, the first address information includes the IP address of the NAT device and the port of the NAT device;
[0109] When the second device and the detection server are not on the same local area network, the second address information includes the IP address of the NAT device and the port of the NAT device.
[0110] Optionally, the first device sends the first address information and the first local address information to the second device based on the signaling server, and the second device obtains a first network address list; the second device sends the second address information and the second local address information to the first device based on the signaling server, and the first device obtains a second network address list, including:
[0111] The first device compares the first address information with the first local address information. If the first address information and the first local address information are consistent, the first device retains either the first address information or the first local address information to obtain first retained address information, and sends the first retained address information to the second device, which then obtains the first network address list. Alternatively, if the first address information and the first local address information are inconsistent, the first device retains both the first address information and the first local address information to obtain first retained address information, and sends the first retained address information to the second device, which then obtains the first network address list.
[0112] The second device compares the second address information with the second local address information. If the second address information matches the second local address information, the second device retains either the second address information or the second local address information to obtain second retained address information, and sends the second retained address information to the first device, so that the first device obtains the second network address list. Alternatively, if the second address information does not match the second local address information, the second device retains both the second address information and the second local address information to obtain second retained address information, and sends the second retained address information to the first device, so that the first device obtains the second network address list.
[0113] Optionally, the communication network address includes:
[0114] The first sub-communication network address of the first device corresponding to the first communication channel and the second sub-communication network address of the second device corresponding to the first communication channel;
[0115] The first sub-communication network address of the first device includes: the IP address of the second device or the corresponding IP address of the NAT device;
[0116] The second sub-communication network address of the second device corresponding to the first communication channel includes: the IP address of the first device or the IP address of the corresponding NAT device.
[0117] Optionally, after establishing the first communication channel between the first device and the second device, and then establishing multiple communication channels between the first device and the second device based on the communication network address corresponding to the first communication channel, the following steps are included:
[0118] When a second communication channel needs to be established, the first device and the second device respectively obtain the communication network address of the first communication channel;
[0119] The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; the second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address.
[0120] The first device receives the port address information of the second port of the first device fed back by the detection server through the second port of the first device; at the same time, the second device receives the port address information of the second port of the second device fed back by the detection server through the second port of the second device.
[0121] The first device determines the port address information of the second port of the second device based on the first valid IP address; the second device determines the port address information of the second port of the first device based on the second valid IP address.
[0122] Based on the port address information of the second port of the first device and the port address information of the second port of the second device, a second communication channel is established between the first device and the second device.
[0123] Optionally, after establishing the first communication channel between the first device and the second device, establishing multiple communication channels between the first device and the second device based on the first network address and the second network address further includes:
[0124] When it is necessary to establish the Nth communication channel, the first device and the second device respectively obtain the communication network address of the first communication channel; where N > 2 and N is an integer;
[0125] The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; the second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address.
[0126] The first device receives the port address information of the Nth port of the first device fed back by the detection server through the Nth port of the first device; at the same time, the second device receives the port address information of the Nth port of the second device fed back by the detection server through the Nth port of the second device.
[0127] The first device determines the port address information of the Nth port of the second device based on the first valid IP address; the second device determines the port address information of the Nth port of the first device based on the second valid IP address.
[0128] Based on the port address information of the Nth port of the first device and the port address information of the Nth port of the second device, the Nth communication channel is established between the first device and the second device.
[0129] Embodiments of this application also provide a computer-readable storage medium, the computer-readable storage medium including a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform the method described above.
[0130] Furthermore, other configurations and functions of the apparatus in the embodiments of this application are known to those skilled in the art, and will not be described in detail here to reduce redundancy.
[0131] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.
[0132] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0133] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0134] In the description of this application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer", "clockwise", "counterclockwise", "axial", "radial", "circumferential", etc., indicating the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application.
[0135] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0136] In this application, unless otherwise expressly specified and limited, the terms "installation," "connection," "joining," and "fixing," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components or the interaction between two components, unless otherwise expressly limited. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.
[0137] In this application, unless otherwise expressly specified and limited, "above" or "below" the second feature can mean that the first feature is in direct contact with the second feature, or that the first feature is in indirect contact with the second feature through an intermediate medium. Furthermore, "above," "on top of," and "over" the second feature can mean that the first feature is directly above or diagonally above the second feature, or simply that the first feature is at a higher horizontal level than the second feature. "Below," "below," and "under" the second feature can mean that the first feature is directly below or diagonally below the second feature, or simply that the first feature is at a lower horizontal level than the second feature.
[0138] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.
Claims
1. A communication method based on the UDP protocol, characterized in that, include: Based on the UDP protocol, the first device receives the first address information fed back by the detection server; Simultaneously, the second device receives the second address information fed back by the detection server; The first device sends the first address information and the first local address information to the second device based on the signaling server, and the second device obtains a first network address list; the second device sends the second address information and the second local address information to the first device based on the signaling server, and the first device obtains a second network address list; Based on the first network address list and the second network address list, a first communication channel is established between the first device and the second device; after the first communication channel is established between the first device and the second device, multiple communication channels are established between the first device and the second device based on the communication network address corresponding to the first communication channel. When a second communication channel needs to be established, the first device and the second device respectively obtain the communication network address of the first communication channel; The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; The second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address; The first device receives the port address information of the second port of the first device fed back by the detection server through the second port of the first device; at the same time, the second device receives the port address information of the second port of the second device fed back by the detection server through the second port of the second device. The first device determines the port address information of the second port of the second device based on the first valid IP address; The second device determines the port address information of the second port of the first device based on the second valid IP address; Based on the port address information of the second port of the first device and the port address information of the second port of the second device, a second communication channel is established between the first device and the second device.
2. The method according to claim 1, characterized in that, The first address information includes the IP address and the first port of the first device; the first local address includes the IP address and the first port of the first device when communicating with the detection server; the second address information includes the IP address and the first port of the second device; the second local address information includes the IP address and the first port of the second device when communicating with the detection server.
3. The method according to claim 1, characterized in that, When the first device and the detection server are not on the same local area network, the first address information includes the IP address of the NAT device and the port of the NAT device; when the second device and the detection server are not on the same local area network, the second address information includes the IP address of the NAT device and the port of the NAT device.
4. The method according to claim 3, characterized in that, The first device sends the first address information and the first local address information to the second device based on the signaling server, and the second device obtains a first network address list; the second device sends the second address information and the second local address information to the first device based on the signaling server, and the first device obtains a second network address list, including: The first device compares the first address information with the first local address information. If the first address information and the first local address information are consistent, the first device retains either the first address information or the first local address information to obtain first retained address information, and sends the first retained address information to the second device, which then obtains the first network address list. Alternatively, if the first address information and the first local address information are inconsistent, the first device retains both the first address information and the first local address information to obtain first retained address information, and sends the first retained address information to the second device, which then obtains the first network address list. The second device compares the second address information with the second local address information. If the second address information matches the second local address information, the second device retains either the second address information or the second local address information to obtain second retained address information, and sends the second retained address information to the first device, so that the first device obtains the second network address list. Alternatively, if the second address information does not match the second local address information, the second device retains both the second address information and the second local address information to obtain second retained address information, and sends the second retained address information to the first device, so that the first device obtains the second network address list.
5. The method according to claim 4, characterized in that, The communication network address includes: The first communication channel corresponds to the first sub-communication network address of the first device and the second sub-communication network address of the second device; wherein, the first sub-communication network address of the first device includes: the IP address of the second device or the IP address of the corresponding NAT device; the second sub-communication network address of the second device corresponding to the first communication channel includes: the IP address of the first device or the IP address of the corresponding NAT device.
6. The method according to claim 5, characterized in that, After establishing the first communication channel between the first device and the second device, establishing multiple communication channels between the first device and the second device based on the first network address and the second network address further includes: When it is necessary to establish the Nth communication channel, the first device and the second device respectively obtain the communication network address of the first communication channel; where N > 2 and N is an integer; The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; the second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address. The first device receives the port address information of the Nth port of the first device fed back by the detection server through the Nth port of the first device; at the same time, the second device receives the port address information of the Nth port of the second device fed back by the detection server through the Nth port of the second device; the first device determines the port address information of the Nth port of the second device based on the first valid IP address; The second device determines the port address information of the Nth port of the first device based on the second valid IP address; and establishes the Nth communication channel between the first device and the second device based on the port address information of the Nth port of the first device and the port address information of the Nth port of the second device.
7. A communication device based on the UDP protocol, characterized in that, include: The receiving module is used for the first device to receive the first address information fed back by the detection server based on the UDP protocol; Simultaneously, the second device receives the second address information fed back by the detection server; The switching module is used for the first device to send the first address information and the first local address information to the second device based on the signaling server, and the second device to obtain a first network address list; the second device to send the second address information and the second local address information to the first device based on the signaling server, and the first device to obtain a second network address list; The determining module is used to establish a first communication channel between the first device and the second device based on the first network address list and the second network address list; The module is configured to establish multiple communication channels between the first device and the second device after establishing the first communication channel between the first device and the second device, based on the communication network address corresponding to the first communication channel. When a second communication channel needs to be established, the first device and the second device respectively obtain the communication network address of the first communication channel; The first device searches for the communication network address of the first communication channel according to the second network address list to determine the first valid IP address; The second device searches for the communication network address of the first communication channel according to the first network address list to determine the second valid IP address; The first device receives the port address information of the second port of the first device fed back by the detection server through the second port of the first device; at the same time, the second device receives the port address information of the second port of the second device fed back by the detection server through the second port of the second device. The first device determines the port address information of the second port of the second device based on the first valid IP address; The second device determines the port address information of the second port of the first device based on the second valid IP address; Based on the port address information of the second port of the first device and the port address information of the second port of the second device, a second communication channel is established between the first device and the second device.
8. An electronic device, characterized in that, The method includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements the method as claimed in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device on which the computer-readable storage medium is located to perform the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for establishing user datagram protocol (UDP) transmission channel
CN115280743A
Method for establishing pier-to-pier direct channels
CN1805388A
Method and apparatus for realizing communication between communication equipments
CN1881916A