CN116346767A - Communication method, electronic equipment and communication system - Google Patents

Communication method, electronic equipment and communication system Download PDF

Info

Publication number
CN116346767A
CN116346767A CN202111596069.1A CN202111596069A CN116346767A CN 116346767 A CN116346767 A CN 116346767A CN 202111596069 A CN202111596069 A CN 202111596069A CN 116346767 A CN116346767 A CN 116346767A
Authority
CN
China
Prior art keywords
port
target device
equipment
target
gain value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111596069.1A
Other languages
Chinese (zh)
Inventor
郝勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Core Ruishi Technology Co ltd
Original Assignee
Shenzhen Core Ruishi Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Core Ruishi Technology Co ltd filed Critical Shenzhen Core Ruishi Technology Co ltd
Priority to CN202111596069.1A priority Critical patent/CN116346767A/en
Publication of CN116346767A publication Critical patent/CN116346767A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2517Translation of Internet protocol [IP] addresses using port numbers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/143Termination or inactivation of sessions, e.g. event-controlled end of session
    • H04L67/145Termination or inactivation of sessions, e.g. event-controlled end of session avoiding end of session, e.g. keep-alive, heartbeats, resumption message or wake-up for inactive or interrupted session

Abstract

The embodiment of the application provides a communication method, electronic equipment and a communication system, wherein the communication method comprises the following steps: receiving a first connection request aiming at target equipment, which is sent by terminal equipment and is used for connecting the target equipment in another local area network; acquiring the number of devices in a local area network where the target device is located, and determining port information of the target device according to the number of the devices, wherein the port information comprises a port gain value or a port range, and the port information is used for determining the port range of the target device; and sending a first connection response to the terminal equipment, wherein the first connection response carries port information of the target equipment. By sending the first connection response carrying the port information of the target device to the terminal device, the terminal device can try to connect the target device according to the port information of the target device, so that the success rate of private network penetration of a large number of devices is improved, namely, when a large number of devices exist in a network corresponding to the target device, the probability of successful connection between the terminal device and the target device is improved.

Description

Communication method, electronic equipment and communication system
Technical Field
The present disclosure relates to the field of computer networks and private network penetration technologies, and in particular, to a communication method, an electronic device, and a communication system.
Background
Network address translation (Network Address Translation, NAT), which is a technique for implementing inter-translation between IP addresses of an internal topology network and addresses of a public network, converts a large number of internal network IP addresses into one or a small number of public network IP addresses, and reduces occupation of the public network IP addresses.
Private network traversal (Private Network Traversal), also known as intranet traversal, NAT traversal, or NAT traversal, is performed to route packets with a particular source IP address and source port number correctly to an intranet host without being masked by a NAT device. That is, since NAT technology hides the real IP address of an intranet host, a host device in a different network needs to perform NAT traversal before communicating.
At present, most private network penetration scenes are designed for the situation that a small number of devices exist in the private network, and in the specific practical process, it is found that among the situations that a large number of devices exist in the private network and require NAT penetration, these situations are as follows: a large number of video playing devices need to be connected with a large number of monitoring camera devices in another intranet, and because the video playing devices and the monitoring camera devices are in different private networks, the video playing devices and the monitoring camera devices need to be connected through a public network, and therefore the video playing devices need to be connected with the monitoring camera devices after the private networks penetrate. In these scenarios, when a large number of devices need to pass through NAT, it takes a long time to try to successfully pass through. It can be seen that the current private network penetration method has low success rate of private network penetration for a large number of devices.
Disclosure of Invention
An object of an embodiment of the present application is to provide a communication method, an electronic device, and a communication system, which are used for improving the problem of low success rate of private network penetration for a large number of devices.
In a first aspect, an embodiment of the present application provides a communication method, including: receiving a first connection request aiming at target equipment, which is sent by terminal equipment and is used for connecting the target equipment in another local area network; acquiring the number of devices in a local area network where the target device is located, and determining port information of the target device according to the number of the devices, wherein the port information comprises a port gain value or a port range, and the port information is used for determining the port range of the target device; and sending a first connection response to the terminal equipment, wherein the first connection response carries port information of the target equipment.
In the implementation process, after the first connection request sent by the terminal equipment and aiming at the target equipment is received, the equipment number in the local area network where the target equipment is located is obtained, port information of the target equipment is determined according to the equipment number, the port information comprises a port gain value or a port range, the terminal equipment can try to connect the target equipment according to the port information of the target equipment by sending a first connection response carrying the port information of the target equipment to the terminal equipment, and therefore the success rate of private network penetration of a large number of equipment is improved, namely when a large number of equipment exists in a network corresponding to the target equipment, the probability of successful connection between the terminal equipment and the target equipment is improved.
In an implementation manner of the first aspect, the first connection request carries a unique identifier of the target device; the method for obtaining the number of the devices in the local area network where the target device is located comprises the following steps: determining the public network IP of the local area network where the target equipment is located according to the unique identification number of the target equipment; and obtaining the number of devices corresponding to the public network IP.
In the implementation process, the public network IP of the local area network where the target equipment is located is determined according to the unique identification number of the target equipment, and the equipment number corresponding to the public network IP is obtained, so that when a large number of equipment exists in the network corresponding to the target equipment, the probability of successful connection between the terminal equipment and the target equipment is improved.
In one implementation manner of the first aspect, the method further includes: according to the received unique identification numbers of the public network IP and the equipment carried in the heartbeat packet, counting the number of the unique identification numbers corresponding to each public network IP, and determining the number of the unique identification numbers corresponding to the public network IP as the number of the equipment corresponding to each public network IP.
In the implementation process, the number of the unique identification numbers corresponding to each public network IP is counted, the number of the unique identification numbers corresponding to the public network IP is determined to be the number of the devices corresponding to each public network IP, so that the problem that the number of the devices corresponding to the public network IP cannot be obtained is avoided, and the probability of successful connection between the terminal device and the target device is improved when a large number of devices exist in the network corresponding to the target device.
In an implementation manner of the first aspect, the method further includes: receiving a reconnection request for target equipment sent by terminal equipment; the port information is adjusted to obtain new port information, and the new port information comprises a new port gain value or a new port range; and sending a reconnection response to the terminal equipment, wherein the reconnection response carries a new port gain value and a first port number which is used by the target equipment recently, or the reconnection response carries a new port range.
In the implementation process, the port information is adjusted to obtain the new port information, and the reconnection response comprising the new port information is sent to the terminal equipment, so that the problem that the terminal equipment is abandoned after connection failure is avoided, the terminal equipment tries to connect again according to the new port information, and the probability of successful connection between the terminal equipment and the target equipment can be effectively improved.
In an implementation manner of the first aspect, the new port gain value is determined according to a retry number of the target device connection; wherein, the more the retry times, the larger the new port gain value; or the new port range is determined according to the retry number of the target device connection; wherein, the more the number of retries, the larger the new port range. That is, the new benefit value is related to the number of retries of the terminal device to connect with the target device.
In one implementation manner of the first aspect, adjusting port information to obtain new port information includes: obtaining retry times of connection of the terminal equipment and the target equipment, and taking the product of the port gain value and the retry times as a new port gain value; or, acquiring the retry times of the connection of the terminal equipment and the target equipment and the adjusting coefficient corresponding to the current network state, and taking the product of the port gain value, the retry times and the adjusting coefficient as a new port gain value.
In the implementation process, the port gain value of the port is further amplified through the adjusting coefficient, so that the port range of the target equipment is enlarged, the probability of successful connection with the target equipment is further improved, and the success rate of private network penetration is improved.
In an implementation manner of the first aspect, the adjustment coefficients corresponding to different network states have different values; when the current network state meets the set requirement, the adjusting coefficient is used for amplifying the port gain value; or when the current network state does not meet the set requirement, the adjusting coefficient is used for reducing the port gain value; wherein the current network state is determined from a distribution of port numbers used by the terminal device.
In a second aspect, an embodiment of the present application further provides a communication method, which is applied to a terminal device, including: sending a first connection request for connecting the target device to the server, wherein the first connection request is used for connecting the target device in another local area network; receiving a first connection response sent by a server, wherein the first connection response carries port information of target equipment, and the port information comprises a port gain value or a port range; and attempting to connect with the target device according to the port information.
In the implementation process, the first connection response carrying the port information of the target device is sent by the receiving server, and the connection is tried with the target device according to the port gain value or the port information of the port range, so that the success rate of private network penetration of a large number of devices is improved, namely, when a large number of devices exist in the network corresponding to the target device, the probability of successful connection between the terminal device and the target device is improved.
In an implementation manner of the second aspect, the port information includes a port gain value, and the first connection response further carries a second port number that is used most recently by the target device; attempting to connect with the target device according to the port information, comprising: determining a sum value of a second port number of the target device and a port gain value as an upper limit value of a port range of the target device, and determining a difference value of the second port number of the target device and the port gain value as a lower limit value of the port range of the target device; determining the port range of the target device according to the upper limit value of the port range and the lower limit value of the port range; and attempting to connect with the target device according to the port range of the target device.
In one implementation manner of the second aspect, attempting to connect with the target device according to the port range includes: generating a plurality of second connection requests according to the public network IP of the target device and a plurality of port numbers in the port range; a plurality of second connection requests is sent to the target device.
In the implementation process, the plurality of second connection requests are generated according to the public network IP of the target device and the plurality of port numbers in the port range, so that the problem of low connection efficiency when only one connection request is sent each time is solved, and when a large number of devices exist in the network corresponding to the target device, the probability of successful connection between the terminal device and the target device is improved.
In an implementation manner of the second aspect, the method further includes: if a second connection response returned by the target equipment is not received within a preset time, a reconnection request for the target equipment is sent to the server; receiving a reconnection response sent by the server, and reattaching connection with the target equipment according to the reconnection response; wherein the reconnection response carries the new port gain value and the newly used first port number of the target device, or the reconnection response carries the new port range.
In the implementation process, the terminal equipment receives the reconnection response sent by the server and reattempts connection with the target equipment according to the reconnection response, so that the problem that the terminal equipment is abandoned after connection failure is avoided, the terminal equipment reattempts connection according to the new port information, and the probability of successful connection between the terminal equipment and the target equipment can be effectively improved.
In a third aspect, embodiments of the present application further provide a communication system, including: the system comprises a server, target equipment and terminal equipment; the server is respectively communicated with the target equipment and the terminal equipment; the server comprises a first processor and a first memory, the first memory storing machine-readable instructions executable by the first processor, which when executed by the first processor perform the method as described above in the first aspect or any one of the possible implementations of the first aspect; the terminal device comprises a second processor and a second memory, the second memory storing machine-readable instructions executable by the second processor, which when executed by the second processor performs the method as described above in the second aspect or any one of the possible implementations of the second aspect.
In a fourth aspect, embodiments of the present application also provide a computer program product comprising computer program instructions which, when read and executed by a processor, perform a method as described above for the first aspect or any one of the possible implementations of the first aspect, or perform a method as described above for the second aspect or any one of the possible implementations of the second aspect.
In a fifth aspect, embodiments of the present application further provide an electronic device, including: a processor and a memory storing machine-readable instructions executable by the processor to perform the method as described above in the first aspect or any one of the possible implementations of the first aspect; alternatively, machine readable instructions, when executed by a processor, perform a method as described above for any one of the possible implementations of the second aspect or the second aspect.
In a sixth aspect, embodiments of the present application also provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs a method as described above in the first aspect or any one of the possible implementations of the first aspect; alternatively, the computer program, when run by a processor, performs the method as described above for the second aspect or any one of the possible implementations of the second aspect.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application, and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort to a person having ordinary skill in the art.
Fig. 1 is a schematic diagram of a network structure of an application scenario applicable to the embodiment of the present application;
fig. 2 is a schematic flow chart of a communication method provided in an embodiment of the present application;
fig. 3 is a schematic diagram of a process of interaction between a server and a terminal device according to an embodiment of the present application.
Detailed Description
The following description of the technical solutions in the embodiments of the present application will be clearly and completely described with reference to the drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, which are generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations. Accordingly, the following detailed description of the embodiments of the present application, which is provided in the accompanying drawings, is not intended to limit the scope of the claimed embodiments of the present application, but is merely representative of selected embodiments of the present application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, are intended to fall within the scope of the embodiments of the present application.
It should be understood that "first" and "second" in the embodiments of the present application are used to distinguish similar objects. It will be appreciated by those of skill in the art that the words "first," "second," and the like do not limit the amount and order of execution, and that the words "first," "second," and the like do not necessarily differ.
Please refer to fig. 1 for a schematic diagram of a network structure of an applicable application scenario provided in an embodiment of the present application; the following describes a network structure of an application scenario to which the communication method is applicable, where the network structure includes: the system comprises a server, terminal equipment and target equipment; the server may communicate with both the terminal device and the target device via the internet via a hypertext transfer protocol (Hyper Text Transfer Protocol, HTTP) or hypertext transfer security protocol (Hyper Text Transfer Protocol Secure, HTTPs), which may be required to communicate with the server via the internet via an egress router (e.g., a first egress router and a second egress router in the figure) when the terminal device and the target device access the internet. The above server may be understood as an intermediary server, and may refer to a server running on a public network or a cloud host providing elastic computing services (Elastic Compute Servie, ECS), etc.
It can be understood that when the terminal device accesses the internet, the terminal device needs to pass through the first exit router, and the first exit router performs NAT operation on the message sent by the terminal device (i.e. converting the intranet address and the port number into the public network address and the port number), so that the NAT-operated data message is mutually communicated with the server, the target device or other devices. Similarly, when accessing the internet, the target device or other devices need to pass through a second exit router, and the second exit router performs NAT operation on the message sent by the target device or other devices (i.e. converting the intranet address and the port number into the public network address and the port number), so that the NAT-operated data message is mutually communicated with the server or the terminal device.
The terminal device in the embodiment of the application can be a personal computer, a tablet personal computer, a mobile phone, a vehicle-mounted computer or mobile internet equipment.
Please refer to fig. 2, which is a schematic flow chart of a communication method provided in an embodiment of the present application; embodiments of the communication method may include:
step S110: the server receives a first connection request sent by the terminal device, wherein the first connection request is used for connecting a target device in another local area network.
The first connection request refers to a connection request sent to the server by the terminal device that needs to connect to the target device. The first connection request may carry the device identifier of the terminal device and the unique identifier of the target device. The unique identification number of the target device may be a serial number of the target device, a media access control address (Media Access Control Address, MAC), or other information capable of uniquely identifying the target device.
In some embodiments of the present application, the target device and the terminal device are in different local area networks, and in general, the egress router of the target device and the egress router of the terminal device are different egress routers, so that the public network IP of the target device (i.e., the IP address of the egress router of the target device) is different from the public network IP of the terminal device (i.e., the IP address of the egress router of the terminal device). In still other scenarios, the exit router of the target device and the exit router of the terminal device are the same exit router, that is, the same exit router has two different public network IP addresses, but the exit router forwards the data packet passed by the target device and the data packet of the terminal device by using different public network IP addresses, where the public network IP of the target device is still different from the public network IP of the terminal device. For ease of understanding and explanation, the following detailed description will be given by taking an example in which the egress router of the target device and the egress router of the terminal device are different egress routers.
Step S120: the server acquires the number of devices in the local area network where the target device is located, and determines port information of the target device according to the number of the devices, wherein the port information comprises a port gain value or a port range.
The number of devices may be used as a port gain value, or the product of the number of devices and a set coefficient may be used as a port gain value, or the sum of the number of devices and a set value may be used as a port gain value, where the set coefficient and the set value may be determined empirically or according to the current network environment.
If the port information includes a port range, S120 may specifically include the server determining a port gain value of the target device according to the number of devices, and determining the port range of the target device according to the port number used by the target device and the port gain value.
The method for determining the port range of the target device according to the port number and the port gain value which are used by the target device recently comprises the following steps: and determining the sum value of the second port number of the target device and the port gain value as the upper limit value of the port range of the target device, determining the difference value of the second port number of the target device and the port gain value as the lower limit value of the port range of the target device, and determining the port range of the target device according to the upper limit value of the port range and the lower limit value of the port range.
Step S130: the server sends a first connection response to the terminal equipment, wherein the first connection response carries port information of the target equipment.
The above step S120 and step S130 will be explained together; the server in the embodiment of the present application may collect heartbeat information (also referred to as keep-alive packets or hello packets) of each device at any time, where the heartbeat information may include: after the server receives the heartbeat information, the heartbeat information can be analyzed, and the equipment identifier, the public network IP address and the Port number obtained by analysis are stored in a database, so that the database can accelerate the process of counting the number of the equipment. The heartbeat information has the function of keeping active (namely telling the server to be in a survival state), and the equipment identification in the heartbeat information can be counted and used by the server, so that the equipment identification corresponds to the number of the equipment in the local area network environment where the terminal equipment is located, and the number of the equipment is the basis for calculating the gain value. The server can collect the heartbeat information of each device at any time, and the number of the device identifications of the same public network IP address analyzed by the heartbeat information is used as the number of the devices, namely the number of all the devices which send the heartbeat information in the local area network where the target device is located; therefore, the server can count the number of devices corresponding to the public network IP of the target device.
In some embodiments of the above step S120, the server may perform statistics according to the unique identifier of the target device parsed in the first connection request, where the embodiments include: the server analyzes the unique identification number of the target device from the first connection request, determines the public network IP of the local area network where the target device is located according to the unique identification number of the target device, and then inquires and counts the number of devices corresponding to the public network IP of the target device in a database, wherein the database records the public network IP and the unique identification number of the devices carried in the received heartbeat packet. And finally, determining the number of the unique identification numbers corresponding to the public network IP as the number of the devices corresponding to each public network IP.
In some embodiments of the step S120, the first connection request may also carry the public network IP of the target device, so the server may parse the public network IP of the target device from the first connection request, and then query the number of devices sending heartbeat information under the public network IP. Because the server stores the equipment identifier, the public network IP address and the port number in the heartbeat information in the database in advance, the database can be used for inquiring and counting the number of data records which are the same as the public network IP of the target equipment and different from the equipment identifier, and determining the number of the data records as the number of the equipment corresponding to the public network IP of the target equipment, wherein the database comprises the public network IP carried in the heartbeat packet received above and the unique identification number of the equipment. It will be appreciated that the public network IP in the database described above may be parsed from previously received heartbeat information. Of course, in a specific practical process, the server may already count the number of data records which are the same as the public network IP of the target device and different from the device identifier in the database in advance, and when the data records need to be used, the number of data records may be directly obtained from the memory.
In some embodiments, the port range of the target device is carried in the first connection response sent by the server, and after the terminal device receives the first connection response, the terminal device attempts to penetrate (i.e. attempts to connect to the target device) within the port range according to the analyzed port range of the target device. In the embodiment, the target equipment is not required to calculate the port range, so that the processing pressure of the terminal equipment is reduced.
In other embodiments, the port gain value of the target device is carried in the first connection response sent by the server, and after the terminal device receives the first connection response, the port range is calculated according to the analyzed port gain value of the target device and the second port number that is used latest by the target device, and penetration is attempted in the port range (i.e. connection of the target device is attempted). In the embodiment, a server is not required to calculate the port range, so that the processing pressure of the server is reduced. It can be appreciated that the terminal device can obtain the second port number that is most recently used by the target device in a variety of ways: for example, the first connection response carries not only the port gain value but also the second port number, and the terminal device can obtain the port gain value and the second port number simultaneously by analyzing the first link response; or the terminal device receives the second port number sent by the server to the terminal device through other modes.
The latest use of the second port number by the target device includes: the destination device sends the second port number used by the heartbeat packet to the server at the latest time, or the destination device sends the second port number used by the connection request packet or other service data packet to the server at the latest time.
In the implementation process, after the first connection request sent by the terminal equipment and aiming at the target equipment is received, the equipment number in the local area network where the target equipment is located is obtained, port information of the target equipment is determined according to the equipment number, the port information comprises a port gain value or a port range, the terminal equipment can try to connect the target equipment according to the port information of the target equipment by sending a first connection response carrying the port information of the target equipment to the terminal equipment, and therefore the success rate of private network penetration of a large number of equipment is improved, namely when a large number of equipment exists in a network corresponding to the target equipment, the probability of successful connection between the terminal equipment and the target equipment is improved.
In the following, the interaction procedure between the server and the terminal device is taken as an example, as shown in fig. 3, the above communication method may include:
step S210: the terminal device sends a first connection request for connecting the target device to the server, the first connection request being used for connecting the target device located in another local area network.
The embodiment of step S210 described above is, for example: this step is similar to step S110 above, and before the server receives the first connection request, the server may further collect heartbeat information of each device (including the terminal device, the target device, and other devices), where the heartbeat information may include: device identification, public network IP address and Port number (Port), etc. Then, the terminal device sends a first connection request of the connection target device to the server through the HTTP protocol or the HTTPs protocol, so that the server returns a first connection response.
Step S220: the server receives a first connection request sent by the terminal equipment, determines the equipment number corresponding to the public network IP of the target equipment according to the first connection request, and then determines the port information of the target equipment according to the equipment number, wherein the port information comprises a port gain value or a port range.
Step S230: the server sends a first connection response to the terminal equipment, wherein the first connection response carries port information of the target equipment.
The implementation principle and implementation of the steps S220 to S230 are similar to those of the steps S110 to S130, and thus, the implementation principle and implementation thereof will not be described again, and reference may be made to the descriptions of the steps S110 to S130, if not clear.
Step S240: the terminal equipment receives a first connection response sent by the server, determines the port range of the target equipment according to the port information of the target equipment carried by the first connection response, and tries to connect with the target equipment according to the port range.
In some examples, the first connection response carries the port number most recently used by the target device and the port gain value of the target device. The terminal equipment analyzes the first connection response, namely, the latest used port number of the target equipment and the port gain value of the target equipment can be determined, and then the port range of the target equipment is determined according to the port number and the port gain value set by the target equipment. The specific method for determining the port range may refer to the content related to the above embodiment, which is not described herein.
In other examples, the first connection response carries a port range of the target device, and the terminal device analyzes the first connection response to determine the port range of the target device.
Optionally, the terminal device may generate a plurality of second connection requests for a plurality of port numbers within a range of a public network IP and a port of the target device at a time, or may sequentially generate a plurality of second connection requests. The terminal equipment sends a plurality of second connection requests to the target equipment at one time, or the terminal equipment sequentially sends a plurality of second connection requests to the target equipment, wherein the plurality of connection requests are used for the terminal equipment to penetrate through the private network of the target equipment, namely to attempt connection with the target equipment through an exit router of the target equipment.
It can be understood that, after the above terminal device performs private network penetration in the port range in the first connection response, if all the ports in the port range fail to attempt, the terminal device may request new port information from the server again, and perform private network penetration according to the new port information. Such an embodiment may include: S310-S360.
Step S310: the terminal equipment judges whether private network penetration on the target equipment is successful or not.
The embodiment of step S310 described above is, for example: the terminal device can judge whether the private network penetration is successful or not according to whether the connection response fed back by the target device is received within the preset time. If the connection response fed back by the target equipment is received within the preset time, the private network penetration is considered to be successful; if the connection response fed back by the target device is not received within the preset time, the private network penetration is considered to be failed.
Step S320: if the private network penetration of the terminal equipment fails, the terminal equipment sends a reconnection request for the target equipment to the server.
The embodiment of step S320 described above is, for example: if the private network penetration of the terminal device fails (for example, the second connection response returned by the target device is not received within a predetermined time period), the terminal device sends a reconnection request for the target device to the server.
Step S330: the server receives the reconnection request sent by the terminal equipment, and adjusts the port information of the target equipment to obtain new port information of the target equipment, wherein the new port information comprises a new port gain value or a new port range.
In some embodiments, the server may expand the port gain value of the target device after receiving the reconnection request to obtain a new port gain value. The server may send the new port gain value to the terminal device carried in a reconnect response. The new port gain value is related to the number of retries of the connection of the terminal device with the target device, i.e. the new port gain value is determined according to the number of retries of the connection of the target device. Alternatively, the larger the number of retries, the larger the new port gain value. For example, the number of retries is positively correlated with the new port gain value. For example, the product of the port gain value corresponding to the last penetration attempt of the terminal device and the retry number may be used as the new port gain value, that is: port gain value x number of retries = new port gain value.
Alternatively, the new port gain value is related not only to the number of retries of the terminal device connection with the target device, but also to the adjustment factor corresponding to the current network state. The larger the adjustment coefficient, the larger the new port gain value. For example, the product of the port gain value, the retry number, and the adjustment coefficient corresponding to the last penetration attempt of the terminal device may be used as the new port gain value, that is: port gain value x number of retries x adjustment coefficient = new port gain value; wherein the adjustment factor is set in accordance with the network status. The adjustment factor may be used to scale up or down the port gain value.
Specifically, when the current network state meets the set requirement, the adjustment coefficient is used for amplifying the port gain value, and the value of the adjustment coefficient can be set to be greater than 1; alternatively, when the current network state does not meet the setting requirement, the adjustment coefficient is used to reduce the port gain value, for example, the adjustment coefficient may be set to a value greater than 0 and less than 1. The current network state is determined here from the distribution of port numbers used by the terminal device. The server can analyze the distribution condition of the ports used when the terminal equipment is communicated with the server, if the port distribution for multiple times of use of the terminal equipment is concentrated, the current network state is considered to meet the set requirement, namely the current network state is good, and the port gain value of the port is further amplified through the adjusting coefficient, so that the port range of the target equipment is enlarged, the probability of successful connection with the target equipment is further improved, and the success rate of private network penetration is improved; if the port distribution used by the terminal equipment for multiple times is discrete, the current network state is not considered to meet the set requirement, namely the current network state is poor, and the port gain value is reduced through the adjustment coefficient, so that the port range of the target equipment is reduced, and the bandwidth resource between the terminal equipment and the target equipment is saved.
Port distribution concentration and port distribution dispersion are relative concepts and can be set according to different situations. For example, multi-use port distribution centralization refers to multi-use of the same port number, or multi-use port number continuity; multiple use port number distribution discreteness refers to multiple use port numbers that are different and discontinuous. For another example, the multi-use port distribution set refers to a difference between every two nearest port numbers in the multi-use port numbers being less than a threshold; the discrete distribution of the port numbers used multiple times means that the difference between two closest port numbers in the port numbers used multiple times is greater than a threshold value, wherein the threshold value is 1 or 2.
Optionally, the server may further determine a new port range of the target device according to the new port gain value of the target device and the port number that is used by the target device at the latest time, and then directly send the new port range to the terminal device in the reconnection response. The specific method for determining the new port range may refer to the relevant content of the above embodiment, and will not be described herein. Alternatively, the more retries, the larger the new port range.
It should be noted that, after receiving the reconnection request of the terminal device, the server may acquire the port gain value of the target device determined last time by adopting different implementation manners, which specifically includes but is not limited to the following manners: the server finds the port gain value of the target device sent to the terminal device at the last time according to the device identification of the terminal device. Or the reconnection request carries the port gain value of the target device sent by the server last time, and the server can acquire the port gain value by analyzing the reconnection request.
It should be further noted that, the server may also acquire the retry times of the terminal device and the target device by adopting different implementation manners, which specifically includes but is not limited to the following manners: the reconnection request can also carry the retry number, and the server acquires the retry number by analyzing the reconnection request; or the heartbeat packet information reported by the terminal equipment to the server carries the retry times, and the server determines the retry times through the heartbeat packet information of the terminal equipment; or the number of retries sent by the server through the mode adopted by the terminal equipment.
Step S340: and the server generates a reconnection response according to the new port information and sends the reconnection response to the terminal equipment.
The reconnection response may carry the new port gain value and the first port number used by the target device recently, or the reconnection response may carry the new port range.
It should be noted that, the first port number and the second port number of the target device that the server sends to the terminal device twice may be the same port number, or may be different port numbers.
Step S350: and the terminal equipment receives the reconnection response sent by the server.
Step S360: and the terminal equipment performs private network penetration on the target equipment again according to the new port information.
The embodiment of the application provides a communication system, which comprises: server, target device and terminal device.
The server communicates with the target device and the terminal device, respectively.
The server comprises a first processor and a first memory, the first memory storing machine-readable instructions executable by the first processor, which when executed by the first processor perform the method as described in steps S110 to S130, steps S220 to S230, and steps S330 to S340 above.
The terminal device comprises a second processor and a second memory, the second memory storing machine-readable instructions executable by the second processor, which when executed by the second processor perform the method as described in step S210, step S240, step S310 to step S320, step S350 to step S360 above.
It should be understood that, the apparatus corresponds to the terminal device in the foregoing embodiment, and is capable of executing each step executed by the terminal device related to the foregoing method embodiment, and specific functions of the apparatus may be referred to the foregoing description, and detailed descriptions are omitted herein as appropriate to avoid repetition. The device includes at least one software functional module that can be stored in memory in the form of software or firmware (firmware) or cured in an Operating System (OS) of the device.
Embodiments of the present application also provide a computer program product comprising computer program instructions which, when read and executed by a processor, perform a method as described above. It should be understood that the program product corresponds to the above-mentioned communication method embodiments, and is capable of executing each step executed by the server or the terminal device, which are related to the above-mentioned method embodiments, and specific functions of the program product may be referred to the above description, and detailed descriptions are omitted herein as appropriate to avoid repetition. The program product comprises at least one software functional module which can be stored in a memory in the form of software or firmware (firmware) or which is solidified in an Operating System (OS) of the program product.
An electronic device provided in an embodiment of the present application includes: a processor and a memory storing machine-readable instructions executable by the processor, which when executed by the processor perform a method as performed by a server or terminal device as described above.
The embodiments of the present application also provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs a method performed by a server or terminal device as above. The computer readable storage medium may be implemented by any type or combination of volatile or nonvolatile Memory devices, such as static random access Memory (Static Random Access Memory, SRAM for short), electrically erasable programmable Read-Only Memory (Electrically Erasable Programmable Read-Only Memory, EEPROM for short), erasable programmable Read-Only Memory (Erasable Programmable Read Only Memory, EPROM for short), programmable Read-Only Memory (Programmable Read-Only Memory, PROM for short), read-Only Memory (ROM for short), magnetic Memory, flash Memory, magnetic disk, or optical disk.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. The apparatus embodiments described above are merely illustrative, for example, of the flowcharts and block diagrams in the figures that illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved.
In addition, the functional modules of the embodiments in the embodiments of the present application may be integrated together to form a single part, or each module may exist alone, or two or more modules may be integrated to form a single part.
In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
The foregoing description is merely an optional implementation of the embodiments of the present application, but the scope of the embodiments of the present application is not limited thereto, and any person skilled in the art may easily think about changes or substitutions within the technical scope of the embodiments of the present application, and the changes or substitutions should be covered in the scope of the embodiments of the present application.

Claims (15)

1. A method of communication, comprising:
receiving a first connection request sent by a terminal device, wherein the first connection request is used for connecting a target device positioned in another local area network;
acquiring the number of devices in a local area network where the target device is located, and determining port information of the target device according to the number of the devices, wherein the port information comprises a port gain value or a port range, and the port information is used for determining the port range of the target device;
and sending a first connection response to the terminal equipment, wherein the first connection response carries port information of the target equipment.
2. The method of claim 1, wherein the first connection request carries a unique identification number of the target device; the obtaining the number of devices in the local area network where the target device is located includes:
determining the public network IP of the local area network where the target equipment is located according to the unique identification number of the target equipment;
and acquiring the number of the devices corresponding to the public network IP.
3. The method according to claim 2, wherein the method further comprises:
counting the number of the unique identification numbers corresponding to each public network IP according to the received unique identification numbers of the public network IP and the equipment carried in the heartbeat packet, and determining the number of the unique identification numbers corresponding to the public network IP as the number of the equipment corresponding to each public network IP.
4. A method according to any one of claims 1 to 3, further comprising:
receiving a reconnection request for the target equipment, which is sent by the terminal equipment;
the port information of the target equipment is adjusted to obtain new port information, wherein the new port information comprises a new port gain value or a new port range;
and sending a reconnection response to the terminal equipment, wherein the reconnection response carries the new port gain value and the first port number which is used by the target equipment recently, or the reconnection response carries the new port range.
5. The method of claim 4, wherein the new port gain value is determined based on a number of retries of the target device connection; wherein the more the retry times, the larger the new port gain value; or alternatively, the process may be performed,
the new port range is determined according to the retry number of the target equipment connection; wherein, the more the retry number, the larger the new port range.
6. The method according to claim 4 or 5, wherein said adjusting the port information to obtain new port information comprises:
obtaining the retry times of the connection of the terminal equipment and the target equipment, and taking the product of the port gain value and the retry times as the new port gain value;
or alternatively, the process may be performed,
and acquiring the retry times of the connection of the terminal equipment and the target equipment and an adjusting coefficient corresponding to the current network state, and taking the product of the port gain value, the retry times and the adjusting coefficient as the new port gain value.
7. The method of claim 6, wherein the adjustment coefficients corresponding to different network states are different in value;
when the current network state meets the set requirement, the adjusting coefficient is used for amplifying the port gain value; or when the current network state does not meet the set requirement, the adjusting coefficient is used for reducing the port gain value; wherein the current network state is determined from a distribution of port numbers used by the terminal device.
8. A communication method, applied to a terminal device, comprising:
sending a first connection request to a server, wherein the first connection request is used for connecting a target device positioned in another local area network;
receiving a first connection response sent by the server, wherein the first connection response carries port information of the target equipment, and the port information comprises a port gain value or a port range;
and attempting connection with the target equipment according to the port information.
9. The method of claim 8, wherein the port information comprises the port gain value, and wherein the first connection response further carries a second port number that was most recently used by the target device; the attempting to connect with the target device according to the port information includes:
determining a sum value of the second port number of the target device and the port gain value as an upper limit value of a port range of the target device, and determining a difference value of the second port number of the target device and the port gain value as a lower limit value of the port range of the target device;
determining a port range of the target device according to the upper limit value of the port range and the lower limit value of the port range;
And attempting to connect with the target equipment according to the port range of the target equipment.
10. The method of claim 9, wherein said attempting to connect with said target device according to said port range comprises:
generating a plurality of second connection requests according to the public network IP of the target device and a plurality of port numbers in the port range;
and sending the plurality of second connection requests to the target device.
11. The method according to any one of claims 8 to 10, further comprising:
if a second connection response returned by the target equipment is not received within a preset time length, a reconnection request for the target equipment is sent to the server;
receiving a reconnection response sent by the server, and reattaching connection with the target equipment according to the reconnection response;
wherein the reconnection response carries a new port gain value of the target device and a first port number that is most recently used by the target device, or the reconnection response carries a new port range of the target device.
12. A communication system, comprising: the system comprises a server, target equipment and terminal equipment; the server is respectively communicated with the target equipment and the terminal equipment;
The server comprising a first processor and a first memory, the first memory storing machine-readable instructions executable by the first processor, which when executed by the first processor, perform the method of any one of claims 1 to 7;
the terminal device comprising a second processor and a second memory, the second memory storing machine-readable instructions executable by the second processor, which when executed by the second processor, perform the method of any of claims 8 to 11.
13. A computer program product comprising computer program instructions which, when read and executed by a processor, perform the method of any one of claims 1 to 7 or perform the method of any one of claims 8 to 11.
14. An electronic device, comprising: a processor and a memory storing machine-readable instructions executable by the processor, which when executed by the processor, perform the method of any one of claims 1 to 7; alternatively, the machine readable instructions, when executed by the processor, perform the method of any of claims 8 to 11.
15. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a computer program which, when executed by a processor, performs the method according to any of claims 1 to 7; alternatively, the computer program, when executed by a processor, performs the method of any of claims 8 to 11.
CN202111596069.1A 2021-12-24 2021-12-24 Communication method, electronic equipment and communication system Pending CN116346767A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111596069.1A CN116346767A (en) 2021-12-24 2021-12-24 Communication method, electronic equipment and communication system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111596069.1A CN116346767A (en) 2021-12-24 2021-12-24 Communication method, electronic equipment and communication system

Publications (1)

Publication Number Publication Date
CN116346767A true CN116346767A (en) 2023-06-27

Family

ID=86890161

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111596069.1A Pending CN116346767A (en) 2021-12-24 2021-12-24 Communication method, electronic equipment and communication system

Country Status (1)

Country Link
CN (1) CN116346767A (en)

Similar Documents

Publication Publication Date Title
USRE49126E1 (en) Real-time adaptive processing of network data packets for analysis
CN109391560B (en) Network congestion notification method, proxy node and computer equipment
US9742667B2 (en) Packet processing method, device and system
US11218382B2 (en) Quality of service monitoring method, device, and system
US9497089B2 (en) Method and device for spreading deep packet inspection result
KR102167613B1 (en) Message push method and device
CN109660637B (en) P2P hole punching transmission method and system, electronic device and computer readable storage medium
US11032122B2 (en) Multicast delay diagnosis method and apparatus
CN110445723B (en) Network data scheduling method and edge node
CN111314179A (en) Network quality detection method, device, equipment and storage medium
EP2582093A1 (en) Method for detecting message loop, routing agent apparatus and networking system
WO2024060408A1 (en) Network attack detection method and apparatus, device and storage medium
US9509777B2 (en) Connection method and management server
KR102178348B1 (en) Network apparatus and edge service discovery method
US10680930B2 (en) Method and apparatus for communication in virtual network
CN110545213A (en) Computer network data flow monitoring system and method
CN113810349B (en) Data transmission method, device, computer equipment and storage medium
CN116346767A (en) Communication method, electronic equipment and communication system
EP2768197A1 (en) Deep packet inspection result dissemination method and device
JP5925287B1 (en) Information processing apparatus, method, and program
CN113411228A (en) Network condition determining method and server
CN107968720B (en) Information transmission method, cloud system and component
CN112543191B (en) Load balancing method and device
US9071507B2 (en) System and method for registering a CIM provider in a CIM system using information of a device to be configured
WO2024022136A1 (en) Network data processing method and apparatus, and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination