Network connection establishment method and apparatus, and electronic device
By determining the target routing device and controlling the network connection based on the number of routing hops when the client and the terminal device are on the same LAN, the problem of establishing a network connection is solved and accurate network connection control is achieved.
Patent Information
- Application Number
- CN202311235501.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-22
- Publication Date
- 2025-03-25
AI Technical Summary
When the client and the terminal device are on the same LAN, how to effectively establish a network connection between the client and the terminal device.
By receiving the network connection request sent by the client, it is determined that the client and the terminal device are on the same LAN, and the target routing device is determined from the routing device of the LAN. Based on the first route hop number passed by the client to the target routing device and the second route hop number passed by the terminal device to the target routing device, the client and the terminal device are controlled to establish a network connection.
It realizes accurate control of network connections based on the relative network location between the client and the terminal device, and solves the problem of how to establish an effective network connection under the same LAN.
Smart Images

Figure CN119697230A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a method, device and electronic device for establishing a network connection. Background Art
[0002] In the security field, users usually access the video in the network camera or network video recorder through a desktop client or mobile phone application (Application, APP), or control the network camera or network video recorder to perform some other operations. Among them, the desktop client or mobile phone can be collectively referred to as the "client", and the network camera or network video recorder can be collectively referred to as the "terminal device".
[0003] In order to enable the client to access the terminal device, it is usually necessary to establish a network connection between the client and the terminal device. Therefore, how to establish a network connection between the client and the terminal device is a problem that needs to be solved urgently by those skilled in the art. Summary of the invention
[0004] The embodiments of the present application provide a method, apparatus and electronic device for establishing a network connection, which are used to solve the problem of how to establish a network connection between a client and a terminal device when the client and the terminal device are in the same local area network.
[0005] In a first aspect, an embodiment of the present application provides a method for establishing a network connection, which may include:
[0006] Receiving a network connection request sent by a client, wherein the network connection request is used to request to establish a network connection with a terminal device;
[0007] In the case where it is determined that the client and the terminal device are in the same local area network, determining a target routing device from routing devices in the local area network, the target routing device being a routing device common to a first network path from the client to the network device and a second network path from the terminal device to the network device;
[0008] Based on the first routing hop count from the client to the target routing device and the second routing hop count from the terminal device to the target routing device, the client is controlled to establish a network connection with the terminal device.
[0009] According to a network connection establishment method provided by the present application, the method controls the client to establish a network connection with the terminal device based on the first routing hop number from the client to the target routing device and the second routing hop number from the terminal device to the target routing device, including:
[0010] When the first routing hop number is 1 and / or the second routing hop number is 1, controlling the client to establish a network connection with the terminal device through the local area network;
[0011] When the first routing hop number is greater than 1 and the second routing hop number is greater than 1, the client is controlled to establish a network connection with the terminal device through a public network.
[0012] According to a network connection establishment method provided by the present application, the step of determining a target routing device from routing devices in the local area network includes:
[0013] Receiving first routing information sent by the client, where the first routing information includes network addresses of all routing devices in the first network path;
[0014] receiving second routing information sent by the terminal device, wherein the second routing information includes network addresses of all routing devices in the second network path;
[0015] The target routing device is determined from the routing devices in the local area network based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path.
[0016] According to a network connection establishment method provided by the present application, the target routing device is determined from the routing devices in the local area network based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path, including:
[0017] Determine a first routing device in the local area network from the first network path based on the network addresses of all routing devices in the first network path;
[0018] Determine a second routing device in the local area network from the second network path based on the network addresses of all routing devices in the second network path;
[0019] The same routing device between the first routing device and the second routing device is determined as the target routing device.
[0020] According to a network connection establishment method provided by the present application, when the number of the identical routing devices is at least two, determining the identical routing device in the first routing device and the second routing device as the target routing device includes:
[0021] For each identical routing device, determine the sum of the number of routing hops from the identical routing device to the client and the number of routing hops from the identical routing device to the terminal device;
[0022] The routing device corresponding to the smallest sum value among at least two identical routing devices is determined as the target routing device.
[0023] According to a network connection establishment method provided by the present application, the target routing device is determined from the routing devices in the local area network based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path, including:
[0024] Determine the same routing device among all routing devices in the first network path and all routing devices in the second network path based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path;
[0025] Among the same routing devices, a routing device in the local area network is determined as the target routing device.
[0026] According to a network connection establishment method provided by the present application, the determining that the client and the terminal device are in the same local area network includes:
[0027] Determine whether the public network address of the client is the same as the public network address of the terminal device;
[0028] When the public network addresses are the same, it is determined that the client and the terminal device are in the same local area network.
[0029] In a second aspect, an embodiment of the present application further provides a network connection establishment device, including:
[0030] A receiving unit, configured to receive a network connection request sent by a client, wherein the network connection request is used to request to establish a network connection with a terminal device;
[0031] a processing unit, configured to determine, when it is determined that the client and the terminal device are in the same local area network, a target routing device from routing devices in the local area network, the target routing device being a routing device common to a first network path from the client to the network device and a second network path from the terminal device to the network device;
[0032] A control unit is used to control the client to establish a network connection with the terminal device based on a first routing hop number from the client to the target routing device and a second routing hop number from the terminal device to the target routing device.
[0033] According to a network connection establishment device provided by the present application, the control unit is specifically used for:
[0034] When the first routing hop number is 1 and / or the second routing hop number is 1, controlling the client to establish a network connection with the terminal device through the local area network;
[0035] When the first routing hop number is greater than 1 and the second routing hop number is greater than 1, the client is controlled to establish a network connection with the terminal device through a public network.
[0036] According to a network connection establishment device provided by the present application, the processing unit is specifically used for:
[0037] Receiving first routing information sent by the client, where the first routing information includes network addresses of all routing devices in the first network path;
[0038] receiving second routing information sent by the terminal device, wherein the second routing information includes network addresses of all routing devices in the second network path;
[0039] The target routing device is determined from the routing devices in the local area network based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path.
[0040] According to a network connection establishment device provided by the present application, the processing unit is specifically used for:
[0041] Determine a first routing device in the local area network from the first network path based on the network addresses of all routing devices in the first network path;
[0042] Determine a second routing device in the local area network from the second network path based on the network addresses of all routing devices in the second network path;
[0043] The same routing device between the first routing device and the second routing device is determined as the target routing device.
[0044] According to a network connection establishment device provided by the present application, the processing unit is specifically used for:
[0045] When the number of the same routing devices is at least two, for each of the same routing devices, determining the sum of the number of routing hops from the same routing device to the client and the number of routing hops from the same routing device to the terminal device;
[0046] The routing device corresponding to the smallest sum value among at least two identical routing devices is determined as the target routing device.
[0047] According to a network connection establishment device provided by the present application, the processing unit is specifically used for:
[0048] Determine the same routing device among all routing devices in the first network path and all routing devices in the second network path based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path;
[0049] Among the same routing devices, a routing device in the local area network is determined as the target routing device.
[0050] According to a network connection establishment device provided by the present application, the processing unit is specifically used for:
[0051] Determine whether the public network address of the client is the same as the public network address of the terminal device;
[0052] When the public network addresses are the same, it is determined that the client and the terminal device are in the same local area network.
[0053] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, a method for establishing a network connection as described in any one of the above items is implemented.
[0054] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the network connection establishment method as described in any one of the above items is implemented.
[0055] In a fifth aspect, an embodiment of the present application further provides a computer program product, including a computer program, which, when executed by a processor, implements a network connection establishment method as described in any one of the above items.
[0056] The network connection establishment method, device and electronic device provided by the embodiment of the present application, the network device receives the network connection request sent by the client, and when it is determined that the client and the terminal device are in the same local area network, the target routing device is determined from the routing devices in the local area network, and the client and the terminal device are controlled to establish a network connection based on the first routing hops from the client to the target routing device and the second routing hops from the terminal device to the target routing device. In this way, based on the relative network position between the client and the terminal device, the client and the terminal device can be accurately controlled to establish a network connection, thereby effectively solving the problem of how to establish a network connection between the client and the terminal device when the client and the terminal device are in the same local area network. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0058] Figure 1 A schematic diagram of a scenario including a client and a terminal device provided for an embodiment of the present application;
[0059] Figure 2 Another schematic diagram of a scenario including a client and a terminal device provided for an embodiment of the present application;
[0060] Figure 3 A flowchart of a method for establishing a network connection provided in an embodiment of the present application;
[0061] Figure 4 A flowchart of a method for determining a target routing device from routing devices in a local area network provided by an embodiment of the present application;
[0062] Figure 5 A schematic diagram of another scenario including a client and a terminal device provided for an embodiment of the present application;
[0063] Figure 6 A schematic diagram of the structure of a network connection establishment device provided in an embodiment of the present application;
[0064] Figure 7 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0065] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0066] In the embodiments of the present application, "at least one" means one or more, and "more" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In the text description of the present application, the character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0067] The technical solution provided by the embodiment of the present application can be applied to the field of security. In the field of security, users usually access the video in the network camera or network video recorder through a desktop client or a mobile phone APP, or control the network camera or network video recorder to perform some other operations. In the subsequent description, the desktop client or the mobile phone can be collectively referred to as a "client", and the network camera or network video recorder can be collectively referred to as a "terminal device". In order to enable the client to access or control the terminal device, it is necessary to establish a network connection between the client and the terminal device.
[0068] For example, in some scenarios, if the area in the scenario is small and one router can cover the entire area, the client and the terminal device can be connected to the network device through one router, that is, the client and the terminal device are in the same subnet in the same LAN. For example, see Figure 1 As shown, Figure 1 A schematic diagram of a scenario including a client and a terminal device is provided for an embodiment of the present application, wherein the local area network includes a subnet 192.168.1.0 / 24, the client and the terminal device are both in the area covered by the subnet 192.168.1.0 / 24, and are connected to the network device through the network address translation NAT (Network Address Translation) routing device 1 in the subnet 192.168.1.0 / 24, the public network routing device 1, ..., the public network routing device n. Among them, the NAT routing device 1 is a local area network routing device.
[0069] For example, in other scenarios, if the area in the scenario is large and one router is not enough to cover the entire area, a router may be connected to the interface of another router through an interface. For example, the client is in the area covered by one router, and the terminal device is in the area covered by another router, that is, the client and the terminal device are connected to the network device through two serially connected routers, and the client and the terminal device are in two different subnets in the same LAN. For example, see Figure 2 As shown, Figure 2 Another scenario diagram including a client and a terminal device provided in an embodiment of the present application, combined with Figure 2As shown, the local area network includes two subnets, one subnet is 192.168.1.0 / 24, and the other subnet is 192.168.2.0 / 24. The client is in the area covered by the subnet 192.168.1.0 / 24, and the terminal device is in the area covered by the subnet 192.168.2.0 / 24. The client is connected to the network device through the NAT routing device 1 in the subnet 192.168.1.0 / 24, the public network routing device 1, ..., the public network routing device n, and the terminal device is connected to the network device through the NAT routing device 2 in the subnet 192.168.2.0 / 24, the NAT routing device 1 in the subnet 192.168.1.0 / 24, the public network routing device 1, ..., the public network routing device n. Among them, the NAT routing device 2 is a local area network routing device.
[0070] For example, the Internet Protocol (IP) address of the client can be 192.168.1.11, and the IP address of the terminal device can be 192.168.2.22. In the subnet 192.168.1.0 / 24, the egress IP of NAT routing device 1 is 11.11.11.11, and the LAN IP is 192.168.1.1; in the subnet 192.168.2.0 / 24, the egress IP of NAT routing device 2 is 192.168.1.12, and the LAN IP is 192.168.2.1.
[0071] Combined with the above Figure 1 or Figure 2 In the scenario shown, the client and the terminal device are in the same local area network. In order to establish a network connection between the client and the terminal device when the client and the terminal device are in the same local area network, an embodiment of the present application provides a method for establishing a network connection. Below, the network connection establishment method provided by the present application will be described in detail through the following specific embodiments. It can be understood that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0072] Embodiment 1
[0073] Figure 3 A flowchart of a method for establishing a network connection provided in an embodiment of the present application is provided. The method for establishing a network connection can be executed by software and / or hardware devices, such as a network connection establishing device, which can be a network device or integrated in a network device. For example, see Figure 3 As shown, the network connection establishment method may include:
[0074] S301: Receive a network connection request sent by a client, where the network connection request is used to request to establish a network connection with a terminal device.
[0075] For example, the network connection request may include an identifier of the terminal device, and may also include a network address of the client, a service port number, etc., which may be specifically set according to actual needs, and the embodiments of the present application do not impose further limitations here.
[0076] For example, when a user accesses a video in a terminal device through a client, or controls the terminal device to perform some other operations, a network connection request can be sent to the network device; alternatively, a network connection request can be periodically sent to the network device so that the network device receives the network connection sent by the client.
[0077] After receiving the network connection request, the network device can first determine whether the client and the terminal device are in the same local area network. If the client and the terminal device are not in the same local area network, the technical solution provided by this application is stopped. This situation is not currently involved in this application; if the client and the terminal device are in the same local area network, the target routing device is further determined from the routing devices in the local area network, that is, the following S302 is executed.
[0078] By way of example, in an embodiment of the present application, when the network device determines whether the client and the terminal device are in the same local area network, it can first obtain the public network address of the client and the public network address of the terminal device respectively, and determine whether the public network address of the client and the public network address of the terminal device are the same; when the public network addresses are different, it is determined that the client and the terminal device are not in the same local area network; when the public network addresses are the same, it is determined that the client and the terminal device are in the same local area network.
[0079] For example, when the network device obtains the public network address of the client, it takes into account that it has established a network connection with the client, and therefore, the network device will record the public network address of the client; when the network device obtains the public network address of the terminal device, in one possible implementation, the terminal device will periodically report its public network address to the network device, so that the network device can obtain the public network address of the terminal device; in another possible implementation, the terminal device has established a long network connection with the network device in advance, and therefore, the network device will record the public network address of the terminal device.
[0080] S302. When it is determined that the client and the terminal device are in the same local area network, a target routing device is determined from routing devices in the local area network, where the target routing device is a routing device common to a first network path from the client to the network device and a second network path from the terminal device to the network device.
[0081] Among them, the target routing device needs to meet two conditions at the same time. One condition is: it is in the local area network and is a local area network routing device; the other condition is: it is both a routing device in the first network path from the client to the network device and a routing device in the second network path from the terminal device to the network device.
[0082] Only when the above two conditions are met at the same time, the target routing device can be determined. Figure 1 As shown, Figure 1 NAT routing device 1 in is the target routing device; combined with Figure 2 As shown, Figure 2 The NAT routing device 1 in is the target routing device.
[0083] After the target routing device is determined, the client and the terminal device can be controlled to establish a network connection based on the first routing hop count from the client to the target routing device and the second routing hop count from the terminal device to the target routing device, that is, the following S303 is executed:
[0084] S303: Based on the first routing hop count from the client to the target routing device and the second routing hop count from the terminal device to the target routing device, control the client to establish a network connection with the terminal device.
[0085] It can be understood that in the embodiment of the present application, based on the first routing hops from the client to the target routing device and the second routing hops from the terminal device to the target routing device, the relative network position between the client and the terminal device can be determined.
[0086] It can be seen that in the embodiment of the present application, the network device receives the network connection request sent by the client, and when it is determined that the client and the terminal device are in the same local area network, the target routing device is determined from the routing devices in the local area network, and the client and the terminal device are controlled to establish a network connection based on the first routing hop number from the client to the target routing device and the second routing hop number from the terminal device to the target routing device. In this way, based on the relative network position between the client and the terminal device, the client and the terminal device can be accurately controlled to establish a network connection, thereby effectively solving the problem of how to establish a network connection between the client and the terminal device when the client and the terminal device are in the same local area network.
[0087] Based on the above Figure 3 In order to facilitate understanding of how to determine the target routing device from the routing devices in the local area network in the above S302, the following will be described. Figure 4 The second embodiment shown describes in detail how to determine a target routing device from routing devices in a local area network.
[0088] Embodiment 2
[0089] Figure 4 A flow chart of a method for determining a target routing device from routing devices in a local area network provided in an embodiment of the present application is provided. For example, see Figure 4 As shown, the method for determining a target routing device may include:
[0090] S401. Receive first routing information sent by a client, where the first routing information includes network addresses of all routing devices in a first network path.
[0091] For example, in an embodiment of the present application, the first routing information may include not only the network addresses of all routing devices in the first network path, but also the network addresses of network devices, which may be specifically set according to actual needs.
[0092] For example, in an embodiment of the present application, the client may obtain the first routing information through a traceroute command; and after obtaining the first routing information, the client may send the first routing information to the network device.
[0093] For example, it can be combined with Figure 2 As shown, in Figure 2 In the scenario shown, the first network path from the client to the network device includes NAT routing device 1, public network routing device 1, ..., and public network routing device n in sequence, connected to the network device. For example, the first routing information sent by the client to the network device can be shown in the following Table 1:
[0094] Table 1
[0095]
[0096] Among them, the network address of NAT routing device 1 in Table 1 is 192.168.1.1, the network address of public network routing device 1 is 22.22.22.22, ..., the network address of public network routing device n is nn.nn.nn.nn, and the network address of the network device is 99.99.99.99, thereby obtaining the first routing information sent by the client.
[0097] S402: Receive second routing information sent by the terminal device, where the second routing information includes network addresses of all routing devices in the second network path.
[0098] For example, in an embodiment of the present application, the second routing information may include not only the network addresses of all routing devices in the second network path, but also the network addresses of network devices, which may be specifically set according to actual needs.
[0099] For example, in an embodiment of the present application, the terminal device may obtain the second routing information through a traceroute command; and after obtaining the second routing information, the terminal device may send the second routing information to the network device.
[0100] For example, it can be combined with Figure 2 As shown, in Figure 2 In the scenario shown, the second network path from the terminal device to the network device includes NAT routing device 2, NAT routing device 1, public network routing device 1, ..., and public network routing device n in sequence, connected to the network device. For example, the second routing information sent by the terminal device to the network device can be shown in the following Table 2:
[0101] Table 2
[0102]
[0103] Among them, the network address of NAT routing device 2 in Table 2 is 192.168.2.1, the network address of NAT routing device 1 is 192.168.1.1, the network address of public network routing device 1 is 22.22.22.22, …, the network address of public network routing device n is nn.nn.nn.nn, and the network address of the network device is 99.99.99.99, thereby obtaining the second routing information sent by the terminal device.
[0104] It should be noted that, in the embodiment of the present application, there is no order between the above S401 and S402. S401 can be executed first, and then S402; S402 can be executed first, and then S401; S401 and S402 can be executed at the same time. The specific settings can be made according to actual needs. Here, the embodiment of the present application is just explained by taking the example of executing S401 first and then executing S402, but it does not mean that the embodiment of the present application is limited to this.
[0105] S403: Determine a target routing device from routing devices in the local area network based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path.
[0106] For example, in an embodiment of the present application, based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path, when determining the target routing device from the routing devices in the local area network, at least two possible implementations may be included:
[0107] In one possible implementation, the network device may first determine a first routing device in a local area network from the first network path based on the network addresses of all routing devices in the first network path; and determine a second routing device in the local area network from the second network path based on the network addresses of all routing devices in the second network path; and then determine the same routing device in the first routing device and the second routing device as the target routing device.
[0108] For example, when determining the first routing device in the local area network from the first network path based on the network addresses of all routing devices in the first network path, the type of network address can be distinguished. For example, network addresses 10.0.0.0~10.255.255.255, 172.16.0.0~172.31.255.255, and 192.168.0.0~192.168.255.255 are network addresses of the local area network. Therefore, the network address of the local area network can be first filtered out from the network addresses of all routing devices in the first network path, and the routing device corresponding to the network address of the local area network can be determined as the first routing device.
[0109] For example, in combination with the above Table 1, the relevant information of determining the first routing device in the local area network from the first network path can be seen in the following Table 3:
[0110] Table 3
[0111]
[0112] The first routing device only includes NAT routing device 1 .
[0113] For example, when determining the second routing device in the local area network from the second network path based on the network addresses of all routing devices in the second network path, similar to the above-mentioned method of determining the first routing device in the local area network from the first network path, the network address of the local area network can be first filtered out from the network addresses of all routing devices in the second network path, and the routing device corresponding to the network address of the local area network can be determined as the second routing device.
[0114] For example, in combination with the above Table 2, the relevant information for determining the second routing device in the local area network from the second network path can be found in the following Table 4:
[0115] Table 4
[0116]
[0117] The second routing device includes a NAT routing device 2 and a NAT routing device 1 .
[0118] In combination with the above description, after respectively determining the first routing device in the local area network from the first network path and determining the second routing device in the local area network from the second network path, the same routing device in the first routing device and the second routing device can be determined as the target routing device. For example, in combination with Table 3 and Table 4, the NAT routing device 1 shared by the first network path and the second network path is the target routing device, and the network address of the target routing device is 192.168.1.1.
[0119] For example, in an embodiment of the present application, when the same routing device in the first routing device and the second routing device is determined as the target routing device, when the number of the same routing devices is one, the same routing device can be directly determined as the target routing device, as shown in the examples shown in Tables 3 and 4 above.
[0120] When the number of identical routing devices is at least two, for each identical routing device, determine the sum of the number of routing hops from the identical routing device to the client and the number of routing hops from the identical routing device to the terminal device; and determine the routing device corresponding to the smallest sum value among at least two identical routing devices as the target routing device.
[0121] For example, there are two identical NAT routing devices, namely NAT routing device a and NAT routing device b. The sum of the number of routing hops from NAT routing device a to the client and the number of routing hops from the same routing device to the terminal device is 2. The sum of the number of routing hops from NAT routing device b to the client and the number of routing hops from the same routing device to the terminal device is 3. Then NAT routing device a is determined as the target routing device.
[0122] It can be seen that in this possible implementation, when determining the target routing device from the routing devices in the local area network, first, based on the address of the network address of the routing device, the first routing device and the second routing device in the local area network are screened from the first network path and the second network path respectively, and then the same routing device is determined from the first routing device and the second routing device, and the same routing device is determined as the target routing device, so that the client and the terminal device can be accurately controlled to establish a network connection based on the first routing hop number from the client to the target routing device and the second routing hop number from the terminal device to the target routing device, thereby effectively solving the problem of how to establish a network connection between the client and the terminal device when the client and the terminal device are in the same local area network.
[0123] In another possible implementation, the same routing devices among all routing devices in the first network path and all routing devices in the second network path can be determined based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path; and then, among the same routing devices, the routing devices in the local area network can be determined as the target routing devices.
[0124] For example, when determining the same routing devices among all routing devices in the first network path and all routing devices in the second network path based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path, the same network address can be determined based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path, and the routing devices corresponding to the same network addresses are determined to be the same routing devices.
[0125] For example, in combination with Table 1 and Table 2 above, the relevant information of the same routing device can be found in Table 5 below:
[0126] Table 5
[0127]
[0128]
[0129] The same routing devices in the first network path and the second network path include: NAT routing device 1, public network routing device 1, ..., and public network routing device n.
[0130] For example, when determining a routing device in a local area network from the same routing device, the type of network address can be distinguished. For example, network addresses 10.0.0.0-10.255.255.255, 172.16.0.0-172.31.255.255, and 192.168.0.0-192.168.255.255 are network addresses of a local area network. Therefore, the network address of the local area network can be firstly screened out from the network addresses of the same routing device, and the routing device corresponding to the network address of the local area network can be determined as the target routing device. For example, in combination with the above Table 5, the routing device in the local area network in Table 5 is NAT routing device 1, and NAT routing device 1 is determined as the target routing device, and the network address of the target routing device is 192.168.1.1.
[0131] For example, in an embodiment of the present application, when the same routing device in the first routing device and the second routing device is determined as the target routing device, when the number of the same routing devices is one, the same routing device can be directly determined as the target routing device, as shown in the example shown in Table 5 above.
[0132] When the number of identical routing devices is at least two, for each identical routing device, determine the sum of the number of routing hops from the identical routing device to the client and the number of routing hops from the identical routing device to the terminal device; and determine the routing device corresponding to the smallest sum value among at least two identical routing devices as the target routing device.
[0133] For example, there are two identical NAT routing devices, namely NAT routing device a and NAT routing device b. The sum of the number of routing hops from NAT routing device a to the client and the number of routing hops from the same routing device to the terminal device is 2. The sum of the number of routing hops from NAT routing device b to the client and the number of routing hops from the same routing device to the terminal device is 3. Then NAT routing device a is determined as the target routing device.
[0134] In this possible implementation, when determining the target routing device from the routing devices in the local area network, first determine the same routing device from the first network path and the second network path based on the network address of the routing device; then determine the routing device in the local area network from the same routing device and determine it as the target routing device, so that the client and the terminal device can be accurately controlled to establish a network connection based on the first routing hop count from the client to the target routing device and the second routing hop count from the terminal device to the target routing device, thereby effectively solving the problem of how to establish a network connection between the client and the terminal device when the client and the terminal device are in the same local area network.
[0135] Based on the above Figure 2 or Figure 3 In the embodiment shown, after determining the target routing device from the routing devices in the local area network, the client and the terminal device can be controlled to establish a network connection based on the first routing hops from the client to the target routing device and the second routing hops from the terminal device to the target routing device.
[0136] For example, in an embodiment of the present application, based on the first routing hop count and the second routing hop count, when the client establishes a network connection with the terminal device, at least the following two possible implementations may be included:
[0137] In a possible implementation manner, when the first routing hop count is 1 and / or the second routing hop count is 1, the client is controlled to establish a network connection with the terminal device through a local area network.
[0138] For example, in this possible implementation, at least the following three possible situations may be included.
[0139] In a possible case, the first routing hop count and the second routing hop count are both 1, and the control client and the terminal device establish a network connection through the local area network.
[0140] When the first routing hop count and the second routing hop count are both 1, it means that the client and the device are in the area covered by the same subnet in the local area network. For example, see Figure 1 In the scenario shown, the local area network includes a subnet 192.168.1.0 / 24, and the client and the terminal device are both in the area covered by the subnet 192.168.1.0 / 24, and are connected to the network device through the NAT routing device 1 in the subnet 192.168.1.0 / 24, the public network routing device 1, ..., the public network routing device n. In this scenario, the client and the terminal device can establish a direct network connection through the local area network, so the network device can control the client and the terminal device to establish a network connection through the local area network.
[0141] For example, when the network device controls the client to establish a network connection with the terminal device through the local area network, the network device can send a network connection establishment instruction to the client, and the network connection establishment instruction includes the network address and service port number of the terminal device, so that the client can establish a network connection with the terminal device based on the network address and service port number of the terminal device. Alternatively, the network device can send a network connection establishment instruction to the terminal device, and the network connection establishment instruction includes the network address and service port number of the client, so that the terminal device can establish a network connection with the client based on the network address and service port number of the client. In this way, not only can the client be accurately controlled to establish a network connection with the terminal device, but also the network connection is established through the local area network, so that the communication between the client and the terminal device is carried out in the local area network, which can effectively improve the quality of network communication.
[0142] In another possible case, the first routing hop count is 2, and the second routing hop count is 1, and the control client and the terminal device establish a network connection through a local area network.
[0143] When the first routing hop count is 2 and the second routing hop count is 1, it means that the client and the device are in the area covered by the subnets of two adjacent layers in the local area network. For example, see Figure 5 As shown, Figure 5Another scenario diagram including a client and a terminal device is provided for an embodiment of the present application, wherein the local area network includes two subnets, the terminal device is in the area covered by subnet 192.168.1.0 / 24, the client is in the area covered by subnet 192.168.2.0 / 24, the terminal device is connected to the network device via NAT routing device 1 in subnet 192.168.1.0 / 24, public network routing device 1, ..., public network routing device n, and the client is connected to the network device via NAT routing device 2 in subnet 192.168.2.0 / 24, NAT routing device 1 in subnet 192.168.1.0 / 24, public network routing device 1, ..., public network routing device n.
[0144] In this scenario, the client's intranet address is 192.168.2.0 / 24. When the terminal device sends a request to 192.168.2.0 / 24, the request will first go to the default gateway (here is NAT routing device 1). Since NAT routing device 1 does not have a special static route to forward the request to 192.168.2.0 / 24 to NAT routing device 2, the request will be passed up to the gateway of NAT routing device 1 (i.e. public network routing device 1) via the WAN port. Therefore, the terminal device cannot access the client through the LAN; and the intranet address of the terminal device is 192.168.1.0 / 24. When the client sends a request to 192.168.1.0 / 24, the request will first go to the default gateway of its subnet (here is NAT routing device 2), because the WAN port of NAT routing device 2 is connected to the LAN port of NAT routing device 1, and NAT routing device 1 acts as the gateway of NAT routing device 2. Since NAT routing device 2 cannot find the intranet address of the terminal device in subnet 192.168.2.0 / 24, the request will be passed upward to NAT routing device 1. At this time, NAT routing device 1 can find the intranet address of the terminal device in subnet 192.168.1.0 / 24, and the request can be directly forwarded to the intranet address. Therefore, the client can access the terminal device through the LAN, and the network device can also control the client and the terminal device to establish a network connection through the LAN.
[0145] For example, when the network device controls the client to establish a network connection with the terminal device through a local area network, the network device can send a network connection establishment instruction to the client, which includes the network address and service port number of the terminal device, so that the client can establish a network connection with the terminal device based on the network address and service port number of the terminal device. Alternatively, the network device can send an establishment instruction to the client, which includes the network address and service port number of the terminal device, and is used to instruct the client to use its service port to send a signaling to the network address and service port of the terminal device. After receiving the request, the terminal device uses the service port that receives the client's request to send a connection instruction to the source network device and port of the request (the network address and port mapped by the client on the NAT routing device 1) based on the source network address and service port of the request (because the client is connected to the NAT routing device 2, the client's request will be mapped to the network address of the NAT routing device 2 in the subnet 192.168.1.0 / 24, and a specific port after being sent through the NAT routing device 2), so as to establish a network connection with the client. In this way, not only can the client and the terminal device be accurately controlled to establish a network connection, but also a network connection can be established through the local area network, so that the communication between the client and the terminal device is carried out in the local area network, which can effectively improve the quality of network communication.
[0146] In another possible case, the first routing hop count is 1, and the second routing hop count is 2, and the control client and the terminal device establish a network connection through a local area network.
[0147] When the first routing hop count is 1 and the second routing hop count is 2, it means that the client and the device are in the area covered by the subnets of two adjacent layers in the local area network. For example, see Figure 2 In the scenario shown, the local area network includes two subnets, the client is in the area covered by subnet 192.168.1.0 / 24, and the terminal device is in the area covered by subnet 192.168.2.0 / 24. The client is connected to the network device through NAT routing device 1 in subnet 192.168.1.0 / 24, public network routing device 1, ..., public network routing device n, and the terminal device is connected to the network device through NAT routing device 2 in subnet 192.168.2.0 / 24, NAT routing device 1 in subnet 192.168.1.0 / 24, public network routing device 1, ..., public network routing device n.
[0148] In this scenario, the intranet address of the terminal device is 192.168.2.0 / 24. When the client sends a request to 192.168.2.0 / 24, the request will first go to the default gateway (here is NAT routing device 1). Since NAT routing device 1 does not have a special static route to forward the request to 192.168.2.0 / 24 to NAT routing device 2, the request will be passed up to the gateway of NAT routing device 1 (i.e. public network routing device 1) via the WAN port. Therefore, the client cannot access the terminal device through the LAN; and the intranet address of the client is 192.168.1.0 / 24. When the terminal device sends a request to 192.168.1.0 / 24, the request will first go to the default gateway of its subnet (here is NAT routing device 2), because the WAN port of NAT routing device 2 is connected to the LAN port of NAT routing device 1, and NAT routing device 1 acts as the gateway of NAT routing device 2. Since NAT routing device 2 cannot find the client's intranet address in subnet 192.168.2.0 / 24, the request will be passed upward to NAT routing device 1. At this time, NAT routing device 1 can find the client's intranet address in subnet 192.168.1.0 / 24, and the request can be directly forwarded to the intranet address. Therefore, the terminal device can access the client through the LAN, and the network device can also control the client and the terminal device to establish a network connection through the LAN.
[0149] For example, when the network device controls the client to establish a network connection with the terminal device through a local area network, the network device can send a network connection establishment instruction to the terminal device, which includes the client's network address and service port number, so that the terminal device can establish a network connection with the client based on the client's network address and service port number. Alternatively, the network device can send an establishment instruction to the terminal device, which includes the network address and service port number of the client, and is used to instruct the terminal device to use its service port to send a signaling to the network address and service port of the client. After the client receives the request, according to the source network address and service port of the request (because the terminal device is connected to the NAT routing device 2, the request of the terminal device will be mapped to the network address of the NAT routing device 2 in the subnet 192.168.1.0 / 24 and a specific port after being sent out via the NAT routing device 2), the client uses the service port that receives the terminal device request to send the establishment instruction to the source network device and port of the request (the network address and port mapped by the terminal device on the NAT routing device 1), thereby establishing a network connection with the terminal device. In this way, not only can the establishment of a network connection between the client and the terminal device be accurately controlled, but also the network connection is established through the local area network, so that the communication between the client and the terminal device is carried out in the local area network, which can effectively improve the quality of network communication.
[0150] In another possible implementation, when the first routing hop count is greater than 1 and the second routing hop count is greater than 1, the client is controlled to establish a network connection with the terminal device through a public network.
[0151] When the first routing hop count is greater than 1 and the second routing hop count is greater than 1, it means that the client and the device are not in the area covered by the subnets of two adjacent layers in the local area network. The client cannot access the terminal device through the local area network, and the terminal device cannot access the client through the local area network. Therefore, the network device controls the client and the terminal device to establish a network connection through the public network.
[0152] For example, when the network device controls the client and the terminal device to establish a network connection through the public network, it can control the client and the terminal device to establish a network connection through the public network through the Session Traversal Utilities for NAT (STUN) server, or it can control the client and the terminal device to establish a network connection through the public network through the Traversal Using Relaysaround NAT (TURN) server. The specific settings can be made according to actual needs.
[0153] The network connection establishment device provided in the present application is described below. The network connection establishment device described below and the network connection establishment method described above can be referenced to each other.
[0154] Figure 6 This is a schematic diagram of a network connection establishment device provided in an embodiment of the present application, which is applied to a network device. For example, see Figure 6 As shown, the network connection establishing device 60 may include:
[0155] The receiving unit 601 is used to receive a network connection request sent by a client, where the network connection request is used to request to establish a network connection with a terminal device.
[0156] Processing unit 602 is used to determine a target routing device from routing devices in the local area network when it is determined that the client and the terminal device are in the same local area network. The target routing device is a routing device shared by a first network path from the client to the network device and a second network path from the terminal device to the network device.
[0157] The control unit 603 is used to control the client to establish a network connection with the terminal device based on the first routing hop number from the client to the target routing device and the second routing hop number from the terminal device to the target routing device.
[0158] Optionally, the control unit 603 is specifically configured to:
[0159] When the first routing hop count is 1 and / or the second routing hop count is 1, controlling the client to establish a network connection with the terminal device through a local area network;
[0160] When the first routing hop count is greater than 1 and the second routing hop count is greater than 1, the client is controlled to establish a network connection with the terminal device through the public network.
[0161] Optionally, the processing unit 602 is specifically configured to:
[0162] The first routing information sent by the client is received, where the first routing information includes network addresses of all routing devices in the first network path.
[0163] The second routing information sent by the terminal device is received, where the second routing information includes network addresses of all routing devices in the second network path.
[0164] Based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path, a target routing device is determined from routing devices in the local area network.
[0165] Optionally, the processing unit 602 is specifically configured to:
[0166] Based on the network addresses of all routing devices in the first network path, a first routing device in the local area network is determined from the first network path.
[0167] Based on the network addresses of all routing devices in the second network path, a second routing device in the local area network is determined from the second network path.
[0168] The same routing device between the first routing device and the second routing device is determined as the target routing device.
[0169] Optionally, the processing unit 602 is specifically configured to:
[0170] When the number of the same routing devices is at least two, for each of the same routing devices, determining the sum of the number of routing hops from the same routing device to the client and the number of routing hops from the same routing device to the terminal device;
[0171] The routing device corresponding to the smallest sum value among at least two identical routing devices is determined as the target routing device.
[0172] Optionally, the processing unit 602 is specifically configured to:
[0173] Determine the same routing device among all routing devices in the first network path and all routing devices in the second network path based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path;
[0174] Among the same routing devices, a routing device in a local area network is determined as a target routing device.
[0175] Optionally, the processing unit 602 is specifically configured to:
[0176] Determine whether the public network address of the client is the same as the public network address of the terminal device;
[0177] If the public network addresses are the same, make sure that the client and the terminal device are in the same local area network.
[0178] The network connection establishing device 60 of the sealing strip provided in the embodiment of the present application can execute the technical solution of the network connection establishing method in any of the above-mentioned embodiments, and its implementation principle and beneficial effects are similar to the implementation principle and beneficial effects of the network connection establishing method. Please refer to the implementation principle and beneficial effects of the network connection establishing method, and no further details will be given here.
[0179] Figure 7 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application, such as Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720 and the memory 730 complete mutual communication through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute a network connection establishment method, which includes: receiving a network connection request sent by a client, the network connection request is used to request to establish a network connection with a terminal device; in the case of determining that the client and the terminal device are in the same local area network, determining a target routing device from routing devices in the local area network, the target routing device being a routing device common to a first network path from the client to the network device and a second network path from the terminal device to the network device; based on the first routing hops from the client to the target routing device and the second routing hops from the terminal device to the target routing device, controlling the client to establish a network connection with the terminal device.
[0180] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.
[0181] On the other hand, the present application also provides a computer program product, which includes a computer program, which can be stored on a computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the network connection establishment method provided by the above methods, and the network connection establishment method includes: receiving a network connection request sent by a client, the network connection request is used to request to establish a network connection with a terminal device; when it is determined that the client and the terminal device are in the same local area network, determining a target routing device from routing devices in the local area network, the target routing device being a routing device shared by a first network path from the client to the network device and a second network path from the terminal device to the network device; based on a first routing hop count from the client to the target routing device, and a second routing hop count from the terminal device to the target routing device, controlling the client to establish a network connection with the terminal device.
[0182] On the other hand, the present application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the network connection establishment method provided by the above-mentioned methods, the network connection establishment method comprising: receiving a network connection request sent by a client, the network connection request being used to request to establish a network connection with a terminal device; when it is determined that the client and the terminal device are in the same local area network, determining a target routing device from routing devices in the local area network, the target routing device being a routing device common to a first network path from the client to the network device and a second network path from the terminal device to the network device; based on a first routing hop count from the client to the target routing device, and a second routing hop count from the terminal device to the target routing device, controlling the client to establish a network connection with the terminal device.
[0183] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0184] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0185] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for establishing a network connection, characterized in that: include: Receiving a network connection request sent by a client, wherein the network connection request is used to request to establish a network connection with a terminal device; In the case where it is determined that the client and the terminal device are in the same local area network, determining a target routing device from routing devices in the local area network, the target routing device being a routing device common to a first network path from the client to the network device and a second network path from the terminal device to the network device; Based on the first routing hop count from the client to the target routing device and the second routing hop count from the terminal device to the target routing device, the client is controlled to establish a network connection with the terminal device.
2. The method for establishing a network connection according to claim 1, characterized in that: The controlling the client to establish a network connection with the terminal device based on the first routing hop count from the client to the target routing device and the second routing hop count from the terminal device to the target routing device comprises: When the first routing hop number is 1 and / or the second routing hop number is 1, controlling the client to establish a network connection with the terminal device through the local area network; When the first routing hop number is greater than 1 and the second routing hop number is greater than 1, the client is controlled to establish a network connection with the terminal device through a public network.
3. The network connection establishment method according to claim 1 or 2, characterized in that: The step of determining a target routing device from routing devices in the local area network comprises: Receiving first routing information sent by the client, where the first routing information includes network addresses of all routing devices in the first network path; receiving second routing information sent by the terminal device, wherein the second routing information includes network addresses of all routing devices in the second network path; The target routing device is determined from the routing devices in the local area network based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path.
4. The method for establishing a network connection according to claim 3, characterized in that: The determining the target routing device from the routing devices in the local area network based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path comprises: Determine a first routing device in the local area network from the first network path based on the network addresses of all routing devices in the first network path; Determine a second routing device in the local area network from the second network path based on the network addresses of all routing devices in the second network path; The same routing device between the first routing device and the second routing device is determined as the target routing device.
5. The method for establishing a network connection according to claim 4, characterized in that: In a case where the number of the identical routing devices is at least two, determining the identical routing device between the first routing device and the second routing device as the target routing device includes: For each identical routing device, determine the sum of the number of routing hops from the identical routing device to the client and the number of routing hops from the identical routing device to the terminal device; The routing device corresponding to the smallest sum value among at least two identical routing devices is determined as the target routing device.
6. The method for establishing a network connection according to claim 3, characterized in that: The determining the target routing device from the routing devices in the local area network based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path comprises: Determine the same routing device among all routing devices in the first network path and all routing devices in the second network path based on the network addresses of all routing devices in the first network path and the network addresses of all routing devices in the second network path; Among the same routing devices, a routing device in the local area network is determined as the target routing device.
7. The network connection establishment method according to claim 1 or 2, characterized in that: The determining that the client and the terminal device are in the same local area network includes: Determine whether the public network address of the client is the same as the public network address of the terminal device; When the public network addresses are the same, it is determined that the client and the terminal device are in the same local area network.
8. A network connection establishment device, characterized in that: include: A receiving unit, configured to receive a network connection request sent by a client, wherein the network connection request is used to request to establish a network connection with a terminal device; a processing unit, configured to determine, when it is determined that the client and the terminal device are in the same local area network, a target routing device from routing devices in the local area network, the target routing device being a routing device common to a first network path from the client to the network device and a second network path from the terminal device to the network device; A control unit is used to control the client to establish a network connection with the terminal device based on a first routing hop number from the client to the target routing device and a second routing hop number from the terminal device to the target routing device.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the network connection establishment method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the network connection establishment method according to any one of claims 1 to 7 is implemented.