Device connection method, apparatus, and electronic device
By pre-storing the IP address and identifier of the connected device in the connecting device, and combining multicast detection and direct wireless network connection, efficient device connection without manual parameter input is achieved, solving the cumbersome connection problem in the existing technology.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-26
- Publication Date
- 2026-03-31
AI Technical Summary
In existing technologies, when establishing a network connection between the connecting device and the connected device, the user needs to manually enter parameters such as the IP address, which makes the process cumbersome.
The connecting device obtains the IP address and identifier of the connected device corresponding to the pre-stored shortcut, establishes a connection directly with the connected device based on this information, and detects the identifier of alternative devices through multicast probing or wireless network direct connection to ensure successful connection.
No manual parameter input by the user is required, which improves the connection efficiency and success rate between the connecting device and the connected device, and simplifies the connection process.
Smart Images

Figure CN119729901B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network communication technology, and in particular to a device connection method, apparatus and electronic device. Background Technology
[0002] Currently, when establishing a network connection between a connecting device and a connected device, the connection method used is as follows: the user manually inputs parameters such as the IP address of the connected device into the connecting device, and then the connecting device establishes a network connection with the connected device based on the parameters input by the user.
[0003] However, the above method requires manual input from the user, and the process of establishing a network connection between the connecting device and the connected device is rather cumbersome. Summary of the Invention
[0004] The purpose of this application is to provide a device connection method, apparatus, and electronic device to improve the efficiency of establishing a connection between the connecting device and the connected device. The specific technical solution is as follows:
[0005] In a first aspect, embodiments of this application provide a device connection method, applied to a connection-end device, the method comprising:
[0006] When a connection command is obtained for the shortcut corresponding to the connected device, the IP address and the identifier of the connected device corresponding to the shortcut are obtained from the pre-stored shortcut.
[0007] A connection is established with the connected device based on the IP address and identifier of the connected device.
[0008] Optionally, establishing a connection with the connected device based on the IP address and identifier of the connected device includes:
[0009] Send a network connection request to the IP address of the connected device;
[0010] If the network connection with the connected device fails via the IP address, the identifier of the alternative device is detected by a preset device detection method.
[0011] If the identifier of the connected device is present among the candidate device identifiers, a connection request is sent to the connected device to establish a connection with the connected device.
[0012] Optionally, the step of detecting the candidate device identifier through a preset device detection method includes:
[0013] The identifiers of devices in the same network as the connection device are obtained through multicast detection and used as candidate device identifiers; or, the identifiers of devices with the wireless network direct connection function enabled within a preset range of the connection device are obtained through wireless network direct connection and used as candidate device identifiers.
[0014] Sending a connection request to the connected device to establish a connection includes:
[0015] If the identifier of the connected device is detected by multicast, obtain the IP address returned by the connected device based on the multicast; then, send a network connection request to the connected device using the IP address returned by the multicast to establish a network connection with the connected device; or,
[0016] When the identifier of the connected device is detected by the wireless network direct connection, a wireless network connection request is sent to the connected device via the wireless network direct connection method to establish a wireless network connection with the connected device.
[0017] Optionally, the method further includes:
[0018] If the multicast fails to detect the identifier of the connected device, the identifier of a device with the wireless network direct connection function enabled within a preset range of the connected device is detected via wireless network direct connection and used as a candidate device identifier; or...
[0019] If the identifier of the connected device is not detected in the direct wireless network connection, the identifier of the device in the same network as the connected device is obtained through multicast detection and used as the alternative device identifier.
[0020] Optionally, before the step of detecting alternative device identifiers through a preset device detection method if the network connection with the connected device fails via the IP address, the method further includes:
[0021] If the IP address is determined to be unavailable based on the response to the network connection request, then the network connection to the connected device is determined to have failed; or,
[0022] If the IP address is determined to be available based on the response to the network connection request, the device identifier corresponding to the IP address is obtained. If the obtained device identifier is different from the identifier of the connected device, the network connection with the connected device is determined to have failed.
[0023] Optionally, after establishing a connection with the connected end device, the method further includes:
[0024] Based on the IP address of the connected device corresponding to the successfully established connection, the IP address of the connected device corresponding to the pre-stored shortcut is updated.
[0025] Optionally, the connected device identifier is generated based on the hardware serial number of the connected device, the initial MAC address of the connected device, or randomly generated. The connected device identifier uniquely identifies the connected device and remains fixed; and / or,
[0026] The step of establishing a connection with the connected device based on the IP address and identifier of the connected device includes:
[0027] Send a network connection request to the IP address of the connected device;
[0028] If the IP address is determined to be available based on the response to the network connection request, the device identifier corresponding to the IP address is obtained. If the obtained device identifier is the same as the identifier of the connected device, a network connection request is sent to the connected device using the IP address of the connected device to establish a network connection; and / or,
[0029] The connecting device also stores the port information of the connected device corresponding to the shortcut. After establishing a connection with the connected device, the method further includes:
[0030] A connection is established with the target application installed on the connected device based on the port information.
[0031] Secondly, embodiments of this application provide a device connection apparatus applied to a connection-end device, the apparatus comprising:
[0032] The information acquisition module is used to acquire the IP address and identifier of the connected device corresponding to the shortcut when a connection instruction is received for the shortcut corresponding to the connected device.
[0033] The connection establishment module is used to establish a connection with the connected device based on the IP address and the identifier of the connected device.
[0034] Optionally, the connection establishment module includes:
[0035] A network connection request sending unit is used to send a network connection request to the IP address of the connected terminal device;
[0036] The first detection unit is used to detect the identifier of a backup device by means of a preset device detection method when the network connection with the connected device fails through the IP address.
[0037] A connection establishment unit is configured to send a connection request to the connected device when the connected device identifier is present in the candidate device identifiers, so as to establish a connection with the connected device.
[0038] Optionally, the first detection unit is specifically used to obtain the identifier of a device in the same network as the connection device through multicast detection, as a candidate device identifier; or, through wireless network direct connection, to detect the identifier of a device that has enabled wireless network direct connection function within a preset range of the connection device, as a candidate device identifier.
[0039] The connection establishment unit is specifically configured to, when the identifier of the connected device is detected by multicast, obtain the IP address returned by the connected device based on the multicast; and send a network connection request to the connected device based on the IP address returned by the multicast to establish a network connection with the connected device; or, when the identifier of the connected device is detected by direct wireless network connection, send a wireless network connection request to the connected device through direct wireless network connection to establish a wireless network connection with the connected device.
[0040] Optionally, the connection establishment module further includes a second detection unit;
[0041] The second detection unit is used to detect, in the case that the identifier of the connected device is not detected by multicast, the identifier of the device with the wireless network direct connection enabled within a preset range of the connected device, and use it as a candidate device identifier; or, in the case that the identifier of the connected device is not detected by wireless network direct connection, the identifier of the device in the same network as the connected device is detected by multicast, and use it as a candidate device identifier.
[0042] Optionally, the connection establishment module further includes a connection status determination unit;
[0043] The connection status determination unit is configured to determine that the network connection with the connected device has failed if the IP address is determined to be unavailable based on the response status of the network connection request; or, if the IP address is determined to be available based on the response status of the network connection request, obtain the device identifier corresponding to the IP address, and determine that the network connection with the connected device has failed if the obtained device identifier is different from the identifier of the connected device.
[0044] Optionally, the device further includes:
[0045] The IP address update module is used to update the IP address of the connected device corresponding to the shortcut in the pre-stored module after establishing a connection with the connected device, based on the IP address of the connected device corresponding to the successful establishment of the connection.
[0046] Optionally, the connected device identifier is generated based on the hardware serial number of the connected device, the initial MAC address of the connected device, or randomly generated. The connected device identifier uniquely identifies the connected device and remains fixed; and / or,
[0047] The connection establishment module is specifically configured to send a network connection request to the IP address of the connected device; if the IP address is determined to be available based on the response to the network connection request, the module obtains the device identifier corresponding to the IP address; if the obtained device identifier is the same as the identifier of the connected device, the module sends a network connection request to the connected device using the IP address of the connected device to establish a network connection; and / or,
[0048] The connection device also stores the port information of the connected device corresponding to the shortcut, and the device also includes a program connection module;
[0049] The program connection module is used to establish a connection with the target application installed on the connected end device based on the port information after the connection is established with the connected end device.
[0050] Thirdly, embodiments of this application provide an electronic device, including:
[0051] Memory, used to store computer programs;
[0052] When a processor executes a program stored in memory, it implements any of the methods described in the first aspect above.
[0053] Beneficial effects of the embodiments in this application:
[0054] In the solution provided in this application, when the connecting device receives a connection command for a shortcut corresponding to the connected device, it can obtain the pre-stored IP address and identifier of the connected device corresponding to the shortcut; and establish a connection with the connected device based on the IP address and identifier of the connected device. Since the connecting device can directly establish a connection with the connected device based on the pre-stored IP address and identifier of the connected device when it receives a connection command for a shortcut corresponding to the connected device, it eliminates the need for the user to manually input parameters such as the IP address of the connected device, thereby improving the efficiency of establishing a connection between the connecting device and the connected device.
[0055] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0056] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0057] Figure 1 A flowchart illustrating a device connection method provided in an embodiment of this application;
[0058] Figure 2 Based on Figure 1 A flowchart illustrating a connection establishment method in the embodiment shown;
[0059] Figure 3 Based on Figure 2 A flowchart illustrating a method for establishing a connection via device detection in the embodiment shown.
[0060] Figure 4 Based on Figure 2 Another flowchart illustrating the method of establishing a connection through device detection in the illustrated embodiment;
[0061] Figure 5 Based on Figure 3 A detailed flowchart illustrating the method of establishing a connection through device detection in the illustrated embodiment;
[0062] Figure 6 Based on Figure 4 A detailed flowchart illustrating the method of establishing a connection through device detection in the illustrated embodiment;
[0063] Figure 7 Based on Figure 2A specific flowchart of the connection establishment method shown in the embodiment;
[0064] Figure 8 A detailed flowchart of a device connection method provided in an embodiment of this application;
[0065] Figure 9 This is a schematic diagram of the structure of a device connection device provided in an embodiment of this application;
[0066] Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0067] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0068] To improve the efficiency of establishing a connection between the connecting device and the connected device, embodiments of this application provide a device connection method, apparatus, electronic device, computer-readable storage medium, and computer program product. The device connection method provided by the embodiments of this application will be introduced first.
[0069] The device connection method provided in this application can be applied to any connection-end device that needs to establish a connection with the connected end device, such as a computer, tablet computer, or mobile phone, etc., without specific limitation. For clarity, it will be referred to as the connection-end device below.
[0070] like Figure 1 As shown, a device connection method is applied to a connection-end device, the method comprising:
[0071] S101, when a connection instruction is obtained for the shortcut corresponding to the connected device, the IP address and identifier of the connected device corresponding to the shortcut are obtained from the pre-stored shortcut.
[0072] S102, establish a connection with the connected device based on the IP address and identifier of the connected device.
[0073] In the solution provided in this application, when the connecting device receives a connection command for a shortcut corresponding to the connected device, it can obtain the pre-stored IP address and identifier of the connected device corresponding to the shortcut; and establish a connection with the connected device based on the IP address and identifier of the connected device. Since the connecting device can directly establish a connection with the connected device based on the pre-stored IP address and identifier of the connected device when it receives a connection command for a shortcut corresponding to the connected device, it eliminates the need for the user to manually input parameters such as the IP address of the connected device, thereby improving the efficiency of establishing a connection between the connecting device and the connected device.
[0074] After establishing a connection with the connected device for the first time, the connecting device can obtain the IP address and identifier of the connected device. Based on these identifiers, it can then generate a shortcut for the connected device. Subsequent times when the connecting device wants to re-establish a connection, it can activate this shortcut to complete the necessary pre- and post-connection operations, thus achieving a quick connection.
[0075] Therefore, when the connecting device receives a connection command for the shortcut corresponding to the connected device, it can activate the shortcut and obtain the pre-stored IP address and identifier of the connected device corresponding to the shortcut.
[0076] In one implementation, when the connecting device generates a shortcut for the connected device based on the IP address and identifier of the connected device, it can write the IP address and identifier of the connected device into the startup parameters of the shortcut. In this way, when the connecting device receives a connection command for the shortcut, it can read the IP address and identifier of the connected device from the startup parameters of the shortcut.
[0077] After obtaining the IP address and identifier of the connected device, the connecting device can establish a connection with the connected device based on these two identifiers. Specifically, the connecting device can first establish a network connection with the connected device using its corresponding shortcut and based on the connected device's IP address. If the network connection fails to establish, it indicates that the IP address of the connected device may have changed. In this case, the connecting device can locate the connected device based on its fixed identifier and thus establish a connection.
[0078] In one implementation, when the connection between the connecting device and the connected device is a connection between an application on the connecting device and an application on the connected device, the connecting device can also pre-store the port information of the connected device corresponding to the shortcut. Based on this, when establishing a connection with the connected device, the connecting device can first establish a device-to-device connection using IP address and device identifier, and then establish a connection between the device and its application based on the port number, thereby realizing the connection between the application on the connecting device and the application on the connected device.
[0079] In the solution provided in this application, when the connecting device receives a connection command for a shortcut corresponding to the connected device, it can directly establish a connection with the connected device based on the pre-stored IP address and identifier of the connected device corresponding to the shortcut, without requiring the user to manually input parameters such as the IP address of the connected device. This improves the efficiency of establishing a connection between the connecting device and the connected device. Furthermore, when the IP address of the connected device remains unchanged, the connecting device can directly establish a connection with the connected device based on the obtained IP address via the shortcut. When the IP address of the connected device changes, the connecting device can also establish a connection based on the obtained identifier of the connected device. Because the identifier of the connected device does not change, even if the MAC address of the connected device changes, the connecting device can still find the connected device based on the fixed identifier and establish a connection. Therefore, this improves the success rate of establishing a connection between the connecting device and the connected device via the shortcut.
[0080] As one implementation method of this application, such as Figure 2 As shown, establishing a connection with the connected device based on the IP address and identifier of the connected device may include:
[0081] S201, a network connection request is sent to the IP address of the connected terminal device.
[0082] After obtaining the IP address and identifier of the connected device, the connecting device can first send a network connection request to the IP address of the connected device to determine whether the IP address is available.
[0083] In one implementation, the connecting device can send a network connection request to the IP address of the connected device, and then monitor whether it receives response data from the connected device within a preset time period. If it receives response data from the connected device within the preset time period, it determines that the IP address is available; if it does not receive response data from the connected device within the preset time period, it determines that the IP address is unavailable.
[0084] S202, if the network connection with the connected device fails through the IP address, the identifier of the alternative device is detected by a preset device detection method.
[0085] If the connecting device cannot establish a network connection with the connected device using the IP address of the connected device, i.e., the network connection fails, it means that the IP address of the connected device may have changed, and it is no longer possible to establish a network connection with the connected device based on the pre-stored IP address of the connected device.
[0086] However, the connected device may still be on the same network as the connecting device, or within the preset range of the connecting device. In this case, the connected device can use the preset device detection method to detect the identifiers of various devices on the same network as the connecting device, or the identifiers of various devices within the preset range of the connecting device, and use them as alternative device identifiers.
[0087] S203, if the identifier of the connected end device exists in the candidate device identifiers, send a connection request to the connected end device to establish a connection with the connected end device.
[0088] Because there may be multiple devices in the same network as the connecting device or within the preset range of the connecting device, and these devices may or may not include the connected device, the connecting device can determine whether there is a connected device among the candidate device identifiers after detecting each candidate device identifier. That is, it can determine whether there is a connected device among the devices in the same network as the connecting device or within the preset range of the connecting device.
[0089] If the candidate device identifier contains the identifier of the connected device, it means that the connected device is in the same network as the connected device, or that the connected device exists among the devices within the preset range of the connected device. Therefore, after determining that the candidate device identifier contains the identifier of the connected device, the connected device can determine the device corresponding to the connected device identifier based on the identifier of the connected device, take it as the connected device, and then send a connection request to the connected device to establish a connection with the connected device.
[0090] The connection method for the connecting device to send a connection request to the connected device and establish a connection can be either to send a connection request to the connected device through a preset connection method and then directly establish a connection with the connected device, or to first send a connection request to the connected device to obtain the IP address of the connecting device, and then establish a network connection with the connected device based on the IP address. No specific limitation is made here.
[0091] If the identifier of the connected device is not among the candidate device identifiers, it means that the connected device is in the same network as the connected device, or that the connected device is not among the devices in the preset range of the connected device. Therefore, after determining that the connected device identifier is not among the candidate device identifiers, the connected device can determine that the connection has failed.
[0092] In the solution provided in this application embodiment, after obtaining the IP address and identifier of the connected device, the connecting device can first attempt to establish a network connection with the connected device based on its IP address. If a network connection can be established, a simple and efficient fast connection can be achieved. If a network connection cannot be established, the connecting device can also detect the identifiers of various candidate devices based on a preset device detection method, and then determine whether the connected device has been detected based on its identifier. If detected, a connection can be established with the connected device based on its identifier, thereby improving the success rate of establishing a connection between the connecting device and the connected device via a shortcut.
[0093] As one implementation of this application, the above-mentioned detection of candidate device identifiers through a preset device detection method may include:
[0094] The identifiers of devices in the same network as the connection device are obtained through multicast detection and used as candidate device identifiers; or, the identifiers of devices with the wireless network direct connection function enabled within a preset range of the connection device are obtained through wireless network direct connection and used as candidate device identifiers.
[0095] Accordingly, the above-mentioned connection establishment with the connected device based on the connected device identifier may include:
[0096] If the identifier of the connected device is detected by multicast, obtain the IP address returned by the connected device based on the multicast; send a network connection request to the connected device based on the IP address returned by the multicast to establish a network connection with the connected device; or, if the identifier of the connected device is detected by direct wireless network connection, send a wireless network connection request to the connected device through direct wireless network connection to establish a wireless network connection with the connected device.
[0097] In one implementation, after the connecting device fails to connect to the network of the connected device via the IP address of the connected device, the connecting device performs a detection using a preset device detection method, and the method for establishing a connection with the connected device can be as follows: Figure 3 As shown:
[0098] S301, the identifier of the device in the same network as the connection device is obtained through multicast detection, and used as the candidate device identifier.
[0099] If the connecting device fails to establish a network connection with the connected device through the IP address of the connected device, it can enable the multicast function to detect the identifiers of devices in the same network as the connecting device, and use them as alternative device identifiers.
[0100] S302, determine whether the identifier of the connected end device exists in the candidate device identifiers. If it exists, proceed to step S303; if it does not exist, determine that the connection has failed.
[0101] After detecting the candidate device identifier, the connecting device can determine whether the connected device identifier exists among the candidate device identifiers, that is, whether the connected device exists among the devices in the same network as the connecting device.
[0102] S303, obtain the IP address returned by the connected device based on the multicast; send a network connection request to the connected device based on the IP address returned by the multicast to establish a network connection with the connected device.
[0103] When the connecting device detects the identifier of the connected device in multicast, that is, when the identifier of the connected device is among the candidate device identifiers, the connecting device can obtain the IP address of the device corresponding to the connected device identifier, that is, obtain the IP address of the connected device. Then, the connecting device can send a network connection request to the connected device based on the IP address to establish a network connection with the connected device.
[0104] In one scenario, the device's response data to multicast may include the device's IP address. In this case, after determining that the connected device identifier exists among the candidate device identifiers, the connecting device can parse the multicast response data of the device corresponding to that connected device identifier, that is, parse the multicast response data of the connected device to obtain the IP address of the connected device.
[0105] When the connection between the connecting device and the connected device is a connection between an application in the connecting device and an application in the connected device, the response data may also include the port number used by the application in the connected device.
[0106] In another scenario, the device's response data to multicast does not include the device's IP address. In this case, after determining that the candidate device identifier contains the identifier of the connected device, the connecting device can send an IP address acquisition request to the device corresponding to that identifier, i.e., the connected device. This causes the connected device to return an IP address to the connecting device based on the IP address acquisition request, thus enabling the connecting device to obtain the IP address of the connected device.
[0107] In another implementation, after the connecting device fails to connect to the network of the connected device via the IP address of the connected device, the connecting device probes using a preset device detection method, and the method for establishing a connection with the connected device can be as follows: Figure 4 As shown:
[0108] S401, by means of wireless network direct connection, detect the identifier of the device that has enabled wireless network direct connection function within the preset range of the connection terminal device, and use it as the candidate device identifier.
[0109] After failing to establish a network connection with the connected device via the IP address of the connected device, the connecting device can determine whether it supports the wireless network direct connection function, that is, whether it supports the Wi-Fi Direct function. If it does, it enables the wireless network direct connection function and detects the identifiers of devices that have enabled the wireless network direct connection function within the preset range of the connecting device through the wireless network direct connection method, which are used as alternative device identifiers.
[0110] S402, determine whether the identifier of the connected end device exists in the candidate device identifiers. If it exists, proceed to step S403; if it does not exist, determine that the connection has failed.
[0111] After detecting the candidate device identifier, the connecting device can determine whether the connected device identifier exists among the candidate device identifiers, that is, whether the connected device exists among the devices that have enabled the wireless network direct connection function within the preset range of the connecting device.
[0112] S403, a wireless network connection request is sent to the connected device via a direct wireless network connection to establish a wireless network connection with the connected device.
[0113] When the connecting device detects the identifier of the connected device through the wireless network direct connection, that is, when the identifier of the connected device is among the candidate device identifiers, it can directly send a wireless network connection request to the connected device through the wireless network direct connection method to establish a wireless network connection with the connected device. In other words, it establishes a Wi-Fi Direct connection with the connected device through the wireless network direct connection method without needing to obtain the IP address of the connected device.
[0114] In the solution provided in this application embodiment, after the connecting device fails to establish a network connection with the connected device through the IP address of the connected device, it can choose to detect the device identifier of the device in the same network as the connecting device through multicast, or it can choose to detect the device identifier of the device with the wireless network direct connection function enabled within the preset range of the connecting device through wireless network direct connection. Then, when the identifier of the connected device is found in the detected device identifier, it can connect to the connected device, thereby improving the success rate of the connecting device establishing a connection with the connected device through a shortcut.
[0115] As one implementation method of this application, such as Figure 5 As shown, after step S302, the method may further include:
[0116] S304, by means of wireless network direct connection, detect the identifier of the device that has enabled wireless network direct connection function within the preset range of the connection terminal device, and use it as the alternative device identifier.
[0117] If the connecting device fails to establish a network connection with the connected device via the IP address of the connected device, and if the connected device's identifier is not detected via multicast (i.e., the connected device's identifier is not among the candidate device identifiers detected by multicast), in order to ensure that the connecting device and the connected device can successfully establish a connection, the connecting device can try to detect the connected device again via a direct wireless network connection.
[0118] Specifically, the connecting device can determine whether it supports the wireless network direct connection function. If it does, it enables the wireless network direct connection function and detects the identifiers of devices that have enabled the wireless network direct connection function within the preset range of the connecting device through the wireless network direct connection method, which are then used as candidate device identifiers.
[0119] S305, determine whether the connected end device identifier exists in the candidate device identifiers. If it exists, proceed to step S306; if it does not exist, proceed to step S307.
[0120] S306, A wireless network connection request is sent to the connected device via a direct wireless network connection to establish a wireless network connection with the connected device.
[0121] Steps S305-S306 are the same as steps S402-S403, and will not be repeated here.
[0122] S307, connection failed.
[0123] If the identifier of the connected device is not found in either the multicast or wireless network direct connection method among the candidate device identifiers, it means that the connected device is in the same network as the connected device and that there is no connected device among the devices within the preset range of the connected device. Therefore, after the connected device determines in step S305 that there is no connected device identifier among the candidate device identifiers, it can proceed to step S307 to determine that the connection has failed.
[0124] In the solution provided in this application embodiment, after the connecting device fails to establish a network connection with the connected device through the IP address of the connected device, it can first detect the identifier of the connected device through multicast. If multicast cannot detect the identifier of the connected device, it can further detect the identifier of the connected device through the wireless network direct connection method. In this way, the connected device can be detected in both the network distance dimension and the real distance dimension, thereby increasing the probability of discovering the connected device and thus increasing the success rate of the connecting device establishing a connection with the connected device through the shortcut.
[0125] As one implementation method of this application, such as Figure 6 As shown, after step S402, the method may further include:
[0126] S404, the identifier of the device in the same network as the connection device is obtained through multicast detection, and used as the candidate device identifier.
[0127] If the connecting device fails to establish a network connection with the connected device through the IP address of the connected device, and if the connected device's identifier is also not detected through the wireless network direct connection method (i.e., the connected device's identifier is not among the candidate device identifiers detected by the wireless network direct connection), in order to ensure that the connecting device and the connected device can successfully establish a connection, the connecting device can re-probe the connected device through multicast.
[0128] Specifically, the connection device can enable multicast functionality and use multicast to detect the identifiers of devices in the same network as the connection device, which can then be used as alternative device identifiers.
[0129] S405, determine whether the connected end device identifier exists in the candidate device identifiers. If it exists, proceed to step S406; if it does not exist, proceed to step S407.
[0130] S406, obtain the IP address returned by the connected device based on the multicast; send a network connection request to the connected device based on the IP address returned by the multicast to establish a network connection with the connected device.
[0131] The steps S405-S406 described above are the same as those S302-S303 described above, and will not be repeated here.
[0132] S407, connection failed.
[0133] If the identifier of the connected device is not found in either the multicast or wireless network direct connection method among the candidate device identifiers, it means that the connected device is in the same network as the connected device and that there is no connected device among the devices within the preset range of the connected device. Therefore, after the connected device determines in step S405 that there is no connected device identifier among the candidate device identifiers, it can proceed to step S407 to determine that the connection has failed.
[0134] In the solution provided in this application embodiment, after the connecting device fails to establish a network connection with the connected device through the IP address of the connected device, it can first detect the identifier of the connected device through the wireless network direct connection method. If the wireless network direct connection method cannot detect the identifier of the connected device, it can further detect the identifier of the connected device through multicast. In this way, the connected device can be detected in both the network distance dimension and the real distance dimension, thereby increasing the probability of discovering the connected device and thus increasing the success rate of the connecting device establishing a connection with the connected device through the shortcut.
[0135] As one implementation method of this application, such as Figure 7 As shown, prior to step S202 above, the method may further include:
[0136] S701, determine whether the IP address is available based on the response to the network connection request. If it is available, proceed to step S702; if it is not available, proceed to step S202.
[0137] After sending a network connection request to the IP address of the connected device, the connecting device can determine whether the IP address is available based on the IP address's response to the network connection request.
[0138] For example, after sending a network connection request to the IP address of the connected device, the connecting device can monitor whether it receives a response from the connected device within a preset time period. If a response is received within the preset time period, the IP address is determined to be available; if no response is received within the preset time period, the IP address is determined to be unavailable.
[0139] If the IP address is determined to be unavailable based on the response to the network connection request, it can be determined that the network connection with the connected device has failed. Then the connecting device can execute step S202, in the case of failure to connect to the network with the connected device via IP address, to detect the identifier of the alternative device through a preset device detection method.
[0140] If the IP address is determined to be available based on the response to the network connection request, the connecting device can execute steps S702-S703 to further determine whether the device currently using the IP address is the connected device.
[0141] S702, obtain the device identifier corresponding to the IP address.
[0142] Once the connection device determines that the IP address is available, it can further obtain the device identifier corresponding to that IP address, that is, obtain the device identifier of the device currently using that IP address.
[0143] In one implementation, the device's response data to the network connection request may include the device's IP address. In this way, after receiving the response data returned from the IP address, the connecting device can determine that the IP address is available and parse the response data to obtain the device identifier corresponding to the IP address.
[0144] In another implementation, the device's response data to the network connection request may not include the device's IP address. In this way, after the connecting device receives the response data returned from the aforementioned IP address and determines that the IP address is available, it can send an IP address acquisition request to the device corresponding to the IP address. This causes the device corresponding to the IP address to return an IP address to the connecting device based on the IP address acquisition request, so that the connecting device can obtain the device identifier corresponding to the IP address.
[0145] S703, determine whether the obtained device identifier is the same as the identifier of the connected end device. If they are the same, proceed to step S704; if they are not the same, proceed to step S202.
[0146] If the device identifier corresponding to the IP address is obtained, it means that a device is currently using the IP address of the connected device. However, this device could be the connected device or another device. Therefore, after obtaining the device identifier corresponding to the IP address, the connecting device can compare the obtained device identifier with the connected device identifier corresponding to the pre-stored shortcut to determine whether the two are the same, that is, to determine whether the device currently using the IP address is the connected device.
[0147] If the obtained device identifier is different from the identifier of the connected device, it means that the device currently using the IP address is not the connected device, and it is determined that the network connection with the connected device has failed. Then the connecting device can execute step S202, in the case of failure to connect to the network of the connected device by IP address, to detect the alternative device identifier by a preset device detection method.
[0148] If the obtained device identifier is different from the identifier of the connected device, it means that the device currently using the IP address is the connected device. At this time, the connecting device can execute step S704.
[0149] S704, a network connection request is sent to the connected device using the IP address of the connected device to establish a network connection with the connected device.
[0150] If the connecting device determines that the IP address of the connected device corresponding to the shortcut is available, and determines that the device identifier corresponding to the obtained IP address is the same as the identifier of the connected device, it means that the connected device is still using the IP address. Therefore, the connecting device can send a network connection request to the connected device through the IP address of the connected device to establish a network connection with the connected device.
[0151] In the solution provided in this application embodiment, the connecting end device can first send a network connection request to the IP address of the connected end device, and then determine whether the IP address is available based on the response to the network connection request. If the IP address is available, it can further determine whether the device currently using the IP address is the connected end device. If the device currently using the IP address is the connected end device, then a network connection request is sent to the connected end device through the IP address of the connected end device to establish a network connection with the connected end device, thereby improving the accuracy of establishing the connection.
[0152] As one embodiment of this application, after establishing a connection with the connected end device as described above, the method may further include:
[0153] Based on the IP address of the connected device corresponding to the successful establishment of the connection, the pre-stored IP address of the connected device is updated.
[0154] To enable subsequent connection processes to quickly establish a connection with the connected device by launching a shortcut and using the IP address of the connected device corresponding to the shortcut, the connecting device can update the pre-stored IP address of the connected device based on the IP address of the connected device corresponding to the successful connection after establishing a connection.
[0155] In one implementation, when the connecting device establishes a network connection with the connected device based on the IP address returned by multicast, since the connected device returns an IP address to the connecting device when responding to the multicast, the connecting device can directly use the IP address returned by multicast as the IP address of the connected device corresponding to the successful establishment of the connection, and then update the pre-stored IP address of the connected device based on this IP address.
[0156] In another implementation, when the connecting device establishes a wireless network connection with the connected device via a direct wireless network connection, since it is not necessary to obtain or use the IP address of the connected device during the establishment of the wireless network connection, the connecting device can send an identifier acquisition request to the IP address of the connected device after establishing the wireless network connection to obtain the IP address of the connected device, use it as the IP address of the connected device corresponding to the successful establishment of the connection, and then update the pre-stored IP address of the connected device based on this IP address.
[0157] In the solution provided in this application embodiment, after establishing a connection with the connected device, the connecting device can update the pre-stored IP address of the connected device based on the IP address of the connected device corresponding to the successful connection. This allows subsequent connection processes to quickly establish a connection with the connected device by launching a shortcut and using the IP address of the connected device corresponding to the shortcut.
[0158] As one embodiment of this application, the identifier of the connected device can be generated based on the hardware serial number of the connected device, the initial MAC address of the connected device, or randomly generated. The identifier of the connected device is used to uniquely identify the connected device and remains fixed.
[0159] In one implementation, the identifier of the connected device can be a GUID (Globally Unique Identifier). The GUID can be generated by directly using the hardware serial number or initial MAC address of the connected device, by adding a random number to the hardware serial number or initial MAC address of the connected device, or by generating a random number and directly using the random number as the GUID. No specific limitation is made here.
[0160] In the method of generating random numbers and directly using the random number as a GUID, in order to avoid generating the same random number, non-random parameters such as time can be added to the random number generation algorithm.
[0161] In the solution provided in this application embodiment, the identifier of the connected device can be generated based on the hardware serial number of the connected device, the initial MAC address of the connected device, or randomly generated, to uniquely identify the connected device, and remains unchanged. In this way, even if the IP address of the connected device changes, or the network card of the connected device is replaced, causing the MAC address of the connected device to change, the connected device can be identified through the device identifier of the connected device because the device identifier is used to uniquely identify the connected device and remains unchanged, thereby enabling the connecting device to establish a connection with the connected device.
[0162] The following is based on Figure 8 For example, let's introduce a device connection method provided in an embodiment of this application:
[0163] When the connecting device receives a connection instruction for the shortcut corresponding to the connected device, it can first activate the shortcut and then execute step S801 to obtain the IP address and GUID from the startup parameters, i.e., obtain the IP address and identifier of the connected device. Then, the connecting device can execute step S802 to determine if the IP address can be used for network connection, i.e., determine if the IP address is available. If it is, the connecting device can execute step S803 to further determine if the device's GUID matches the GUID in the startup parameters, i.e., determine if the device identifier corresponding to the obtained IP address is the same as the identifier of the connected device in the shortcut's startup parameters. If they are the same, a network connection request can be sent to the connected device using the connected device's IP address to establish a network connection. Then, step S804 can be executed to confirm a successful connection.
[0164] If the judgment result of step S802 or step S803 is negative, the connecting device can execute step S806, multicast detection device, that is, obtain the identifier of the device in the same network as the connecting device through multicast detection, as a candidate device identifier. Then the connecting device can execute step S807, filter the existence of the device by GUID, that is, determine whether the identifier of the connected device exists among the candidate device identifiers. If it exists, the IP address returned by the connected device based on multicast can be obtained. Through this IP address, a network connection request is sent to the connected device to establish a network connection with the connected device. Then step S804 can be executed to confirm the connection is successful.
[0165] If not, the connecting device can execute step S808 to determine whether Wi-Fi Direct is supported, i.e., whether it has Wi-Fi Direct functionality. If not, the connecting device can execute step S812 to determine that the connection has failed. If supported, it can execute step S809 to detect devices via Wi-Fi Direct, i.e., to detect the identifiers of devices with Wi-Fi Direct enabled within the preset range of the connecting device via wireless network direct connection, and use them as candidate device identifiers. Then, it can execute step S810 to filter whether devices exist by GUID, i.e., to determine whether the identifier of the connected device exists among the candidate device identifiers. If not, it executes step S812 to determine that the connection has failed. If it exists, it executes step S811 to establish a Wi-Fi Direct connection, i.e., to send a wireless network connection request to the connected device via wireless network direct connection to establish a wireless network connection with the connected device. Then, it executes step S804 to determine that the connection is successful.
[0166] After the connecting device successfully connects to the connected device via multicast or direct wireless network connection, the IP address of the connected device changes. Therefore, the connecting device can execute step S805 to update the shortcut startup parameters after the connection is successful. That is, based on the IP address of the connected device corresponding to the successfully established connection, the connecting device updates the IP address of the pre-stored shortcut corresponding to the connected device.
[0167] After completing step S805 to update the shortcut startup parameters or after completing step S812 to confirm the connection failure, the device connection method execution ends.
[0168] In the solution provided in this application embodiment, when the connecting device receives a connection instruction for a shortcut corresponding to the connected device, it can obtain the pre-stored IP address and identifier of the connected device corresponding to the shortcut; and establish a connection with the connected device based on the IP address and identifier of the connected device. Since the connecting device can obtain the IP address and identifier of the connected device when it receives the connection instruction for the shortcut, when the IP address of the connected device remains unchanged, the connecting device can directly establish a connection with the connected device based on the obtained IP address via the shortcut. When the IP address of the connected device changes, the connecting device can still establish a connection based on the obtained identifier of the connected device. Because the identifier of the connected device does not change, even if the MAC address of the connected device changes, the connecting device can still find the connected device based on the fixed identifier and establish a connection. Therefore, the success rate of the connecting device establishing a connection with the connected device via the shortcut is improved.
[0169] Corresponding to the above-described device connection method, this application also provides a device connection apparatus, which will be described below.
[0170] like Figure 9 As shown, a device connection apparatus is applied to a connection-end device, the apparatus comprising:
[0171] The information acquisition module 910 is used to acquire the IP address and identifier of the connected device corresponding to the shortcut when a connection instruction is obtained for the shortcut corresponding to the connected device.
[0172] The connection establishment module 920 is used to establish a connection with the connected device based on the IP address and the identifier of the connected device.
[0173] In the solution provided in this application, when the connecting device receives a connection command for a shortcut corresponding to the connected device, it can obtain the pre-stored IP address and identifier of the connected device corresponding to the shortcut; and establish a connection with the connected device based on the IP address and identifier of the connected device. Since the connecting device can directly establish a connection with the connected device based on the pre-stored IP address and identifier of the connected device when it receives a connection command for a shortcut corresponding to the connected device, it eliminates the need for the user to manually input parameters such as the IP address of the connected device, thereby improving the efficiency of establishing a connection between the connecting device and the connected device.
[0174] As one embodiment of this application, the connection establishment module 920 described above may include:
[0175] A network connection request sending unit is used to send a network connection request to the IP address of the connected terminal device;
[0176] The first detection unit is used to detect the identifier of a backup device by means of a preset device detection method when the network connection with the connected device fails through the IP address.
[0177] A connection establishment unit is configured to send a connection request to the connected device when the connected device identifier is present in the candidate device identifiers, so as to establish a connection with the connected device.
[0178] As one embodiment of this application, the first detection unit described above can be specifically used to detect the identifier of a device that is in the same network as the connection device through multicast, and use it as a candidate device identifier; or, through wireless network direct connection, detect the identifier of a device that has enabled wireless network direct connection function within a preset range of the connection device, and use it as a candidate device identifier.
[0179] The connection establishment unit described above can be specifically used to obtain the IP address returned by the connected device based on the multicast when the multicast detects the identifier of the connected device; and send a network connection request to the connected device based on the IP address returned by the multicast to establish a network connection with the connected device; or, when the wireless network direct connection detects the identifier of the connected device, send a wireless network connection request to the connected device through the wireless network direct connection method to establish a wireless network connection with the connected device.
[0180] As one embodiment of this application, the connection establishment module 920 may further include a second detection unit;
[0181] The aforementioned second detection unit is used to detect, in the case where the connected device identifier is not detected by multicast, the identifier of a device that has enabled the wireless network direct connection function within a preset range of the connected device, and use it as a candidate device identifier; or, in the case where the connected device identifier is not detected by wireless network direct connection, the identifier of a device that is in the same network as the connected device, and use it as a candidate device identifier.
[0182] As one embodiment of this application, the connection establishment module 920 may further include a connection status determination unit;
[0183] The aforementioned connection status determination unit is used to determine that the network connection with the connected device has failed if the IP address is determined to be unavailable based on the response status of the network connection request; or, if the IP address is determined to be available based on the response status of the network connection request, the unit obtains the device identifier corresponding to the IP address, and determines that the network connection with the connected device has failed if the obtained device identifier is different from the identifier of the connected device.
[0184] As one embodiment of this application, the above-described apparatus may further include:
[0185] The IP address update module is used to update the IP address of the connected device corresponding to the shortcut in the pre-stored module after establishing a connection with the connected device, based on the IP address of the connected device corresponding to the successful establishment of the connection.
[0186] As one embodiment of this application, the aforementioned connected device identifier is generated based on the hardware serial number of the connected device, the initial MAC address of the connected device, or randomly generated. The connected device identifier is used to uniquely identify the connected device and remains fixed; and / or,
[0187] The connection establishment module 920 described above can be specifically used to send a network connection request to the IP address of the connected device; if the IP address is determined to be available based on the response to the network connection request, it obtains the device identifier corresponding to the IP address; if the obtained device identifier is the same as the identifier of the connected device, it sends a network connection request to the connected device using the IP address of the connected device to establish a network connection; and / or,
[0188] The aforementioned connection device may also store port information of the connected device corresponding to the shortcut, and the device may also include a program connection module;
[0189] The aforementioned program connection module is used to establish a connection with the target application installed on the connected end device based on the port information after the connection is established with the connected end device.
[0190] This application also provides an electronic device, such as... Figure 10 As shown, it includes:
[0191] Memory 1001 is used to store computer programs;
[0192] When the processor 1002 executes the program stored in the memory 1001, it implements the device connection method described in any of the above embodiments.
[0193] In the solution provided in this application, when the connecting device receives a connection command for a shortcut corresponding to the connected device, it can obtain the pre-stored IP address and identifier of the connected device corresponding to the shortcut; and establish a connection with the connected device based on the IP address and identifier of the connected device. Since the connecting device can directly establish a connection with the connected device based on the pre-stored IP address and identifier of the connected device when it receives a connection command for a shortcut corresponding to the connected device, it eliminates the need for the user to manually input parameters such as the IP address of the connected device, thereby improving the efficiency of establishing a connection between the connecting device and the connected device.
[0194] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 1002, the communication interface, and the memory 1001 communicating with each other via the communication bus.
[0195] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0196] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0197] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0198] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0199] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the device connection method described in any of the above embodiments.
[0200] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the device connection method described in any of the above embodiments.
[0201] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.
[0202] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0203] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0204] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A device connection method characterized by, The method applied to a connection end device comprises: When a connection instruction for a shortcut corresponding to a connected end device is acquired, an IP address and a connected end device identifier of the connected end device corresponding to the shortcut are acquired, wherein the IP address and the connected end device identifier are stored in a start parameter of the shortcut; A connection with the connected end device is established based on the IP address and the connected end device identifier of the connected end device; The connection with the connected end device based on the IP address and the connected end device identifier of the connected end device comprises: A network connection request is sent to the IP address of the connected end device; If the network connection with the connected end device through the IP address fails, an alternative device identifier is obtained through a preset device detection mode; If the alternative device identifier contains the connected end device identifier, a connection request is sent to the connected end device to establish a connection with the connected end device.
2. The method of claim 1, wherein, The alternative device identifier obtained through the preset device detection mode comprises: An identifier of a device in the same network as the connection end device is obtained through multicast detection as the alternative device identifier; or an identifier of a device in a preset range of the connection end device and starting a wireless network direct connection function is obtained through a wireless network direct connection mode as the alternative device identifier; The connection request sent to the connected end device to establish a connection with the connected end device comprises: In a case where the connected end device identifier is detected through multicast, an IP address returned by the connected end device based on the multicast is acquired; a network connection request is sent to the connected end device through the IP address returned by the connected end device based on the multicast to establish a network connection with the connected end device; or In a case where the connected end device identifier is detected through wireless network direct connection, a wireless network connection request is sent to the connected end device through the wireless network direct connection mode to establish a wireless network connection with the connected end device.
3. The method of claim 2, wherein, The method further comprises: In a case where the connected end device identifier is not detected through multicast, an identifier of a device in a preset range of the connection end device and starting a wireless network direct connection function is obtained through the wireless network direct connection mode as the alternative device identifier; or In a case where the connected end device identifier is not detected through wireless network direct connection, an identifier of a device in the same network as the connection end device is obtained through multicast detection as the alternative device identifier.
4. The method according to any one of claims 1 to 3, characterized in that, Before the alternative device identifier is obtained through the preset device detection mode if the network connection with the connected end device through the IP address fails, the method further comprises: In a case where the IP address is determined to be unavailable based on a response to the network connection request, it is determined that the network connection with the connected end device fails; or In a case where the connected end device identifier is not detected through the preset device detection mode, it is determined that the network connection with the connected end device fails. In a case where it is determined that the IP address is available based on a response to the network connection request, a device identifier corresponding to the IP address is acquired, and in a case where the acquired device identifier is different from the connected-end device identifier, it is determined that the network connection with the connected-end device fails.
5. The method according to any one of claims 1 to 3, wherein After the connection with the connected-end device is established, the method further includes: Based on the IP address of the connected-end device corresponding to the successful connection, the IP address of the connected-end device corresponding to the shortcut is updated.
6. The method according to any one of claims 1 to 3, wherein The connected-end device identifier is generated based on a hardware serial number of the connected-end device, an initial MAC address of the connected-end device, or randomly, the connected-end device identifier is used to uniquely identify the connected-end device and is fixed and unchanged. And / or, The connection with the connected-end device based on the IP address and the connected-end device identifier of the connected-end device includes: sending a network connection request to the IP address of the connected-end device; In a case where it is determined that the IP address is available based on a response to the network connection request, a device identifier corresponding to the IP address is acquired, and in a case where the acquired device identifier is different from the connected-end device identifier, it is determined that the network connection with the connected-end device fails. The connected-end device also stores port information of the connected-end device corresponding to the shortcut, and after the connection with the connected-end device is established, the method further includes: Based on the port information, a connection is established with a target application program installed in the connected-end device.
7. A device connection apparatus, characterized by comprising: The device is applied to a connected-end device and includes: An information acquisition module is configured to, when a connection instruction corresponding to a shortcut of a connected-end device is acquired, acquire an IP address and a connected-end device identifier of the connected-end device corresponding to the shortcut which are stored in a start parameter of the shortcut. A connection establishment module is configured to establish a connection with the connected-end device based on the IP address and the connected-end device identifier of the connected-end device. The connection establishment module includes: A network connection request sending unit is configured to send a network connection request to the IP address of the connected-end device. A first detection unit is configured to, when the network connection with the connected-end device through the IP address fails, detect an alternative device identifier through a preset device detection manner. A connection establishment unit is configured to, when the alternative device identifier includes the connected-end device identifier, send a connection request to the connected-end device to establish a connection with the connected-end device.
8. The device of claim 7, wherein The first detecting unit is specifically configured to detect, as an alternative device identifier, an identifier of a device in the same network as the connection-end device through groupcast detection, or detect, as an alternative device identifier, an identifier of a device that has enabled a wireless network direct connection function within a preset range of the connection-end device through a wireless network direct connection manner. The connection establishing unit is specifically configured to, in a case where the connection-end device identifier is detected through groupcast, acquire an IP address returned by the connection-end device based on the groupcast, and send a network connection request to the connection-end device through the IP address returned by the connection-end device based on the groupcast, so as to establish a network connection with the connection-end device; or, in a case where the connection-end device identifier is detected through a wireless network direct connection, send a wireless network connection request to the connection-end device through a wireless network direct connection manner, so as to establish a wireless network connection with the connection-end device; or, The connection establishing module further comprises a second detecting unit. The second detecting unit is configured to, in a case where the connection-end device identifier is not detected through groupcast, detect, as an alternative device identifier, an identifier of a device that has enabled a wireless network direct connection function within a preset range of the connection-end device through a wireless network direct connection manner; or, in a case where the connection-end device identifier is not detected through a wireless network direct connection, detect, as an alternative device identifier, an identifier of a device in the same network as the connection-end device through groupcast; or, The connection establishing module further comprises a connection condition determining unit. The connection condition determining unit is configured to, in a case where it is determined that the IP address is not available based on a response to the network connection request, determine that the network connection with the connection-end device fails; or, in a case where it is determined that the IP address is available based on the response to the network connection request, acquire a device identifier corresponding to the IP address, and in a case where the acquired device identifier is different from the connection-end device identifier, determine that the network connection with the connection-end device fails; or, The apparatus further comprises: An IP address updating module configured to, after the connection with the connection-end device is established, update a pre-stored IP address of the connection-end device corresponding to the shortcut based on an IP address of the connection-end device corresponding to the successful connection; or, The connection-end device identifier is generated based on a hardware serial number of the connection-end device, an initial MAC address of the connection-end device, or randomly, the connection-end device identifier is used to uniquely identify the connection-end device and is fixed and unchanged; and / or The connection establishing module is specifically configured to send a network connection request to an IP address of the connection-end device, acquire a device identifier corresponding to the IP address in a case where it is determined that the IP address is available based on a response to the network connection request, and if the acquired device identifier is the same as the connection-end device identifier, send a network connection request to the connection-end device through the IP address of the connection-end device, so as to establish a network connection; and / or, The connection end device also stores port information of the connected end device corresponding to the shortcut, and the device further comprises a program connection module; The program connection module is configured to, after the connection with the connected end device is established, establish a connection with a target application program installed in the connected end device based on the port information.
9. An electronic device, comprising: The computer program product comprises: A memory for storing a computer program; A processor for executing the program stored in the memory to implement the method of any one of claims 1-6.
Citation Information
Patent Citations
Network connection method and apparatus, and electronic device
CN115776711A