CN116828030A - Network connection method, device, storage medium and electronic equipment - Google Patents
Network connection method, device, storage medium and electronic equipment Download PDFInfo
- Publication number
- CN116828030A CN116828030A CN202210278519.0A CN202210278519A CN116828030A CN 116828030 A CN116828030 A CN 116828030A CN 202210278519 A CN202210278519 A CN 202210278519A CN 116828030 A CN116828030 A CN 116828030A
- Authority
- CN
- China
- Prior art keywords
- electronic equipment
- network connection
- area network
- wide area
- electronic device
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 67
- 238000004891 communication Methods 0.000 claims abstract description 55
- 238000001514 detection method Methods 0.000 claims description 20
- 238000012544 monitoring process Methods 0.000 claims description 10
- 238000004590 computer program Methods 0.000 claims description 8
- 238000010586 diagram Methods 0.000 description 12
- 230000006870 function Effects 0.000 description 7
- 230000008569 process Effects 0.000 description 7
- 230000005540 biological transmission Effects 0.000 description 6
- 239000004973 liquid crystal related substance Substances 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000004140 cleaning Methods 0.000 description 1
- 230000001419 dependent effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000008520 organization Effects 0.000 description 1
- 238000009877 rendering Methods 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 238000010408 sweeping Methods 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/143—Termination or inactivation of sessions, e.g. event-controlled end of session
- H04L67/145—Termination or inactivation of sessions, e.g. event-controlled end of session avoiding end of session, e.g. keep-alive, heartbeats, resumption message or wake-up for inactive or interrupted session
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L43/00—Arrangements for monitoring or testing data switching networks
- H04L43/50—Testing arrangements
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
- H04L67/148—Migration or transfer of sessions
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Health & Medical Sciences (AREA)
- Cardiology (AREA)
- General Health & Medical Sciences (AREA)
- Mobile Radio Communication Systems (AREA)
Abstract
The embodiment of the application discloses a network connection method, a device, a storage medium and electronic equipment, wherein the method comprises the following steps: when a trigger instruction for communication connection with second electronic equipment is received, detecting whether the first electronic equipment is in a wide area network connection state; if the first electronic equipment is in the wide area network connection state, detecting whether the second electronic equipment is in the wide area network connection state; if the second electronic equipment is also in a wide area network connection state, establishing wide area network connection with the second electronic equipment; and if the second electronic equipment is not in the wide area network connection state, establishing local area network connection with the second electronic equipment. By adopting the embodiment of the application, the network connection state between the first electronic equipment and the second electronic equipment can be adaptively switched, and the stability and the reliability of the communication between the equipment are ensured.
Description
Technical Field
The present application relates to the field of network technologies, and in particular, to a network connection method, a device, a storage medium, and an electronic apparatus.
Background
The network connection state of the electronic device is divided into an intranet connection state and an extranet connection state. The intranet, also called local area network (Local Area Network, LAN), is a computer communication network formed by interconnecting a plurality of electronic devices within a local geographical area (such as a school, factory, or organization), for example, within a few kilometers of a square circle. Protocols suitable for local area network communications include transmission control protocol (Transmission Control Protocal, TCP), address resolution protocol (Address Resolution Protocol, ARP), and the like. The external network, also called a wide area network (Wide Area Network, WAN), is a remote network that connects computers in local or metropolitan area networks of different areas. Typically span a large physical range, ranging from tens of kilometers to thousands of kilometers, which can connect multiple areas, cities and countries, or span several continents and provide long-range communications, forming an international long-range network. Protocols suitable for wide area network communications include message queue telemetry transport protocol (Message Queuing Telemetry Transport, MQTT) and the like. When an electronic device communicates with other electronic devices, it is important to select an appropriate network connection.
Disclosure of Invention
The embodiment of the application provides a network connection method, a device, a storage medium and electronic equipment, which can realize self-adaptive switching of network connection states between first electronic equipment and second electronic equipment and ensure stability and reliability of communication between the equipment. The technical scheme is as follows:
in a first aspect, an embodiment of the present application provides a network connection method, where the method includes:
when a trigger instruction for communication connection with second electronic equipment is received, detecting whether the first electronic equipment is in a wide area network connection state;
if the first electronic equipment is in the wide area network connection state, detecting whether the second electronic equipment is in the wide area network connection state;
if the second electronic equipment is also in a wide area network connection state, establishing wide area network connection with the second electronic equipment;
if the second electronic equipment is not in the wide area network connection state, local area network connection is established with the second electronic equipment, and the first electronic equipment and the second electronic equipment are in the same local area network.
In a second aspect, an embodiment of the present application provides another network connection method, where the method includes:
Monitoring the connection state of the wide area network of the second electronic equipment;
when a trigger instruction of communication connection with the second electronic device, which is sent by the first electronic device, is received, the wide area network connection state of the second electronic device is sent to the first electronic device, so that the first electronic device establishes network connection with the second electronic device based on the wide area network connection state of the second electronic device.
In a third aspect, an embodiment of the present application provides a network connection device, including:
the first detection module is used for detecting whether the first electronic equipment is in a wide area network connection state or not when a trigger instruction for communication connection with the second electronic equipment is received;
the second detection module is used for detecting whether the second electronic equipment is in a wide area network connection state or not if the first electronic equipment is in the wide area network connection state;
the wide area connection module is used for establishing wide area network connection with the second electronic equipment if the second electronic equipment is also in a wide area network connection state;
and the local area connection module is used for establishing local area network connection with the second electronic equipment if the second electronic equipment is not in a wide area network connection state, and the first electronic equipment and the second electronic equipment are in the same local area network.
In a fourth aspect, an embodiment of the present application provides another network connection device, including:
the monitoring connection module is used for monitoring the wide area network connection state of the second electronic equipment;
and the state sending module is used for sending the wide area network connection state of the second electronic equipment to the first electronic equipment when receiving a trigger instruction which is sent by the first electronic equipment and is used for carrying out communication connection with the second electronic equipment, so that the first electronic equipment establishes network connection with the second electronic equipment based on the wide area network connection state of the second electronic equipment.
In a fifth aspect, embodiments of the present application provide a computer storage medium storing a plurality of instructions adapted to be loaded by a processor and to perform the above-described method steps.
In a sixth aspect, an embodiment of the present application provides an electronic device, which may include: a processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and to perform the above-mentioned method steps.
The technical scheme provided by the embodiments of the application has the beneficial effects that at least:
According to the application, the network connection state of the first electronic equipment is detected in real time, the network connection state of the second electronic equipment is further obtained, and the connection state between the first electronic equipment and the second electronic equipment is switched to be local area network connection or wide area network connection, so that good communication and data communication between the first electronic equipment and the second electronic equipment are always kept, the method has good adaptability in a complex working environment, and bad experience brought by disconnection to users is avoided.
Drawings
In order to more clearly illustrate the embodiments of the application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a schematic diagram of an architecture of an electronic device connected through a wide area network according to an embodiment of the present application;
fig. 2 is a schematic diagram of an architecture of an electronic device connected through a lan according to an embodiment of the present application;
fig. 3 is a schematic view of a scenario of electronic device connection according to an embodiment of the present application;
Fig. 4 is a schematic view of another scenario of electronic device connection provided in an embodiment of the present application;
fig. 5 is a schematic flow chart of a network connection method according to an embodiment of the present application;
fig. 6 is a schematic diagram of a scenario for acquiring a trigger instruction according to an embodiment of the present application;
fig. 7 is a flow chart of another network connection method according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a network connection device according to an embodiment of the present application;
fig. 9 is a schematic structural diagram of another network connection device according to an embodiment of the present application;
fig. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
In the description of the present application, it should be understood that the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. In the description of the present application, it should be noted that, unless expressly specified and limited otherwise, "comprise" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus. The specific meaning of the above terms in the present application will be understood in specific cases by those of ordinary skill in the art. Furthermore, in the description of the present application, unless otherwise indicated, "a plurality" means two or more. "and/or", describes an association relationship of an association object, and indicates that there may be three relationships, for example, a and/or B, and may indicate: a exists alone, A and B exist together, and B exists alone. The character "/" generally indicates that the context-dependent object is an "or" relationship.
The present application will be described in detail with reference to specific examples.
In the present application, as shown in fig. 1, an architecture diagram of a wide area network connection provided in an embodiment of the present application includes: the server 103 establishes wide area network connection with the first electronic device 101 and the second electronic device 102 respectively, in other words, the first electronic device 101 and the second electronic device 102 are connected through the server 103 in a transit manner. It is understood that the number and types of the first electronic device 101, the second electronic device 102, and the server 103 shown in fig. 1 are only illustrative, and the present application also includes any other type of electronic device.
The server 102 may be understood as a server or a cluster of multiple servers, where the server 102 is configured to receive an access request through a plurality of access interfaces configured to provide corresponding data or services to the first electronic device 101 and the second electronic device 102 based on the request content of the access request. The plurality of servers may be a plurality of physical servers, and the plurality of physical servers are independent in hardware; or multiple servers are in multiple virtual servers, the multiple virtual servers are deployed in the same hardware resource pool, and the deployment modes of the virtual servers include but are not limited to: VMware, virtual Box, and Virtual PC.
The first electronic device 101 and the second electronic device 102 (Terminal device) include, but are not limited to, a Mobile Station (MS), a Mobile Terminal device (Mobile Terminal), a Mobile phone (Mobile phone), a handset (handset), and a portable device (portable equipment), and the first electronic device may communicate with one or more wide area network servers via a radio access network (Radio Access Network, RAN). For example, the first electronic device 101 may be a mobile phone (or "cellular" phone), a computer with wireless communication capabilities, etc., and may also be a portable, pocket, hand-held, computer-built-in or vehicle-mounted mobile apparatus or device. As shown in fig. 1, the first electronic device 101 includes a mobile phone, a tablet, a computer, and the like, and the second electronic device 102 includes a mobile phone, a tablet, a computer, a camera, a projector, an air conditioner that can connect a wide area network and a local area network, and the like. It is understood that the types of the first electronic device 101 and the second electronic device 102 may be the same or different, and the present application is not limited in this respect.
In the application, the electronic device 102 can be further provided with a display device and a camera, wherein the display device can be various devices capable of realizing a display function, and the camera is used for collecting video data; for example: the display device may be a cathode ray tube display (Cathode raytubedisplay, CR), a Light-emitting diode display (Light-emitting diodedisplay, LED), an electronic ink screen, a liquid crystal display (Liquid crystal display, LCD), a plasma display panel (Plasma displaypanel, PDP), or the like. The user may utilize the display device on the first electronic device 101 to view displayed text, pictures, videos, etc. and send trigger instructions to the first electronic device 101 via the input device.
As shown in fig. 2, an architecture diagram of an electronic device connected through a lan according to an embodiment of the present application includes: a first electronic device 101 and a second electronic device 102. The first electronic device 101 and the second electronic device 102 are described with reference to fig. 1, and are not described herein.
The first electronic device 101 and the second electronic device 102 are connected by a lan through lan protocols. The local area network protocol includes: transmission control protocol/internet protocol (ransmission Control Protocol/Internet Protocol, TCP/IP), schrex' S Network System (XNS) -based sequential packet protocol (Internet Protocol/Sequenced Packet Protocol, IPX/SPX), netBios enhanced user interface protocol (NetBios Enhanced User Interface, netBEUI), and the like.
Through the lan connection, the first electronic device 101 and the second electronic device 102 can still communicate, including data exchange, acquisition requests, transmission requests, and so on.
In real life, people often use communication between devices to accomplish a number of events. For example, as shown in fig. 3, a schematic view of a scene of device connection provided by an embodiment of the present application includes a first electronic device 1011, a portable computer, a first electronic device 1012, a tablet computer, a second electronic device 1021, a sweeping robot, a second electronic device 1022, an intelligent desk lamp, a second electronic device 1023, an intelligent air conditioner, a second electronic device 1023, a projector, and a second electronic device 1024, and an electronic picture frame. A user communicates with the plurality of second electronic devices 102 through the first electronic device 1011 and/or the electronic device 1012 to complete playing music, switching on/off an air conditioner, cleaning a sanitary, etc., and the first electronic device 101 and the second electronic device 102 are connected through a wide area network or a local area network, and the first electronic device 101 and the second electronic device 102 are in the same local area network.
As another example, as shown in fig. 4, a schematic view of another device connection scenario provided in an embodiment of the present application includes: the electronic device 201, the electronic device 202, the electronic device 203, the electronic device 204, the electronic device 205 and the electronic device 206 are located in the same local area network, and any two electronic devices can communicate through the local area network or the wide area network, so that a user corresponding to each electronic device can communicate with other users through the electronic device, for example, file receiving and sending, notification transmission, video call and the like.
However, due to the complexity of real life scenarios, it is difficult to ensure that the first electronic device and the second electronic device are always in a certain fixed network connection state. For example, as shown in the scenario of fig. 4, when a nearby communication base station is damaged, the electronic device cannot communicate with other electronic devices through the wide area network, which may pose many troubles to the user.
In one embodiment, as shown in fig. 5, a network connection method is specifically proposed, which is applied to a first electronic device, and which may be implemented in dependence on a computer program, and may be run on a network connection device based on von neumann system. The computer program may be integrated in the application or may run as a stand-alone tool class application.
Specifically, the network connection method includes:
and S101, detecting whether the first electronic equipment is in a wide area network connection state or not when a trigger instruction for communication connection with the second electronic equipment is received.
And when the first electronic equipment receives a trigger instruction for communication connection with the second electronic equipment, starting to detect whether the first electronic equipment is in a wide area network connection state. The trigger instruction may be any trigger instruction preset or input by a user. For example, as shown in fig. 6, a schematic view of a scenario for acquiring a trigger instruction provided in an embodiment of the present application includes a first electronic device 101, a mobile phone, and a second electronic device 102, where the first electronic device 101 displays an application interface as shown in the drawing, and when a user selects a control "game mode" or a control "music mode" through a touch display screen of the first electronic device 101, the first electronic device 101 receives the trigger instruction for performing communication connection with the second electronic device 102, and the first electronic device 101 starts to detect whether the first electronic device 101 is in a wide area network connection state. In another embodiment, when the first electronic device detects a trigger instruction for the user to switch the page displayed by the first electronic device from the background page to the foreground page, for example, to switch the page from the application page to the desktop page, based on the trigger instruction, the first electronic device starts to detect the network connection state of the first electronic device, that is, detects whether the first electronic device is in the wide area network connection state.
It will be appreciated that the application interface shown in fig. 6 is only one possible implementation, and the application is not limited in any way, and that the application also includes other types of triggering instructions.
In one embodiment, the method includes detecting whether the first electronic device is in a wide area network connection state by reading a value of a network status flag of the first electronic device. For example, when the first electronic device detects that the value of the network state flag bit AppLocalNet of the first electronic device is 0, judging that the first electronic device is not in a wide area network connection state at this time, commonly called off-network; when the first electronic equipment detects that the value of the network state flag bit AppLocalNet of the first electronic equipment is 1, the first electronic equipment is judged to be in a wide area network connection state at the moment, and communication can be carried out with the server.
In another embodiment, before detecting whether the first electronic device is in the wide area network connection state by reading the value of the network status flag bit, the method further includes: when the network detection device of the first electronic equipment detects that the network connection state of the first electronic equipment is changed, changing the numerical value of the network state zone bit of the first electronic equipment.
Specifically, the first electronic device detects whether the first electronic device is in the wide area network connection state by the network detection device, and determines whether the first electronic device is in the wide area network connection state by, for example, detecting a packet loss rate, a success rate, or the like at the time of communication by the network detection device. Further, when the first electronic device is detected to be in the wide area network connection state, the network status flag bit of the first electronic device is marked as a first value, for example, marked as 1, and when the second electronic device is detected to be not in the wide area network connection state, the network status flag bit of the first electronic device is marked as a second value, for example, marked as 0.
Limited to hardware techniques, the time required to detect whether a first electronic device is in a wide area network connected state is greater than the frequency time for the first electronic device to communicate with other electronic devices. Therefore, whether the first electronic device is in the wide area network connection state is detected based on the preset frequency, when the network connection state of the first electronic device is changed, the network zone bit of the first electronic device is changed, and when the first electronic device communicates with other electronic devices based on the frequency smaller than the preset frequency, only the numerical value of the network state zone bit of the first electronic device is detected, so that the communication with the other electronic devices through the wide area network or the local area network is judged. By adopting the asynchronous detection mode, the communication efficiency is greatly improved, and the inquiry waiting time during communication is reduced.
S102, establishing local area network connection with the second electronic equipment.
In the application, the first electronic device and the second electronic device are in the same local area network. It is understood that the first electronic device and the second electronic device are connected to the same switch or hub or router, or that the IP and subnet mask of the first electronic device and the IP and subnet mask of the second electronic device are in compliance with the same local area network.
And if the first electronic equipment is not in the wide area network connection state, establishing local area network connection with the second electronic equipment. Specifically, a local area network connection is established with the second electronic device based on the IP address and port information of the second electronic device. For example, according to the TCP/IP protocol, the first electronic device establishes a local area network connection with the second electronic device through the IP address and port information of the second electronic device.
In one embodiment, before establishing a local area network connection with the second electronic device based on the IP address and port information of the second electronic device, the method further includes: and acquiring the IP address and port information of the second electronic equipment. For example, the IP address and port information of the second electronic device are read from the memory of the first electronic device.
For another example, the IP address and port information of the second electronic device broadcast by the second electronic device according to the preset frequency is received. When the first electronic device and the second electronic device are connected through the WiFi and TCP protocol, after the first electronic device and/or the second electronic device are disconnected and reconnected with the WiFi, the router allocates a new IP address to the reconnected first electronic device and/or second electronic device, and the connection between the router and the second electronic device is not possible based on the IP address of the second electronic device stored in the first electronic device, so that the first electronic device receives the IP address and port information of the second electronic device broadcast by the second electronic device according to the preset frequency, and when the IP address of the second electronic device changes, the local area network connection is timely reestablished with the second electronic device. The second electronic device may broadcast the IP address and port information of the second electronic device through a multicast protocol mDNS, where the mDNS protocol resolves the second electronic device into an IP address in a small lan that does not include a local name server, which is a zero configuration service, and uses a programming interface, packet format, and operation semantics that are substantially the same as the unicast domain name system DNS.
In another embodiment, after receiving the second trigger instruction, the IP address and the port information of the second electronic device are obtained through the multicast protocol mDNS in response to the second trigger instruction. The second trigger instruction comprises a preset instruction or an instruction input by a user. For example, the second trigger instruction is that the first electronic device detects that a WiFi disconnection and reconnection occurs, or the first electronic device acquires the IP address and port information of the second electronic device when detecting that the IP address of the first electronic device changes, so that when the IP address of the second electronic device changes, the local area network connection is timely reestablished with the second electronic device.
In another embodiment, when establishing a lan connection with the second electronic device, it is required to detect whether the first electronic device is in a lan connection state, that is, whether the first electronic device satisfies a lan connection condition. For example, it is detected whether the first electronic device is in a WiFi connection state. When the first electronic device is not in the lan connection state, the first electronic device cannot be connected with the second electronic device through the wan or lan, and other communication modes, such as NFC communication, bluetooth communication, wired communication, and the like, need to be adopted.
And S103, if the first electronic equipment is in the wide area network connection state, detecting whether the second electronic equipment is in the wide area network connection state.
When the first electronic device is in the wide area network connection state, the first electronic device is connected with a server providing the wide area network connection state, so that whether the second electronic device is in the wide area network connection state is detected. I.e. the wide area network connection status of the second electronic device is obtained from the server. For example, the wide area network connection state of the second electronic device actively reported by the server is received, that is, the server sends the wide area network connection state of the second electronic device to the first electronic device based on the preset frequency.
In another embodiment, a method for obtaining, by a second electronic device, a wide area network connection state of the second electronic device from a server includes: after receiving the first trigger instruction, responding to the first trigger instruction, sending a request for inquiring the wide area network connection state of the second electronic equipment to the server, and receiving the wide area network connection state of the second electronic equipment returned by the server. The first trigger instruction includes any one of a preset instruction or an instruction input by a user, for example, a scene diagram of acquiring the trigger instruction shown in fig. 6, and when the user selects a control "game mode" or a control "music mode" through a touch display screen of the first electronic device 101, the first electronic device 101 receives the trigger instruction for performing communication connection with the second electronic device 102, and the first electronic device 101 starts to detect whether the first electronic device 101 is in a wide area network connection state and detects whether the second electronic device 102 is in a wide area network connection state.
And S104, if the second electronic equipment is also in the wide area network connection state, establishing wide area network connection with the second electronic equipment.
And acquiring the wide area network connection state of the second electronic equipment through the server. For example, receiving an equipment state flag bit AppLocalDeviceStatus sent by a server, and when the equipment state flag bit is a first value, judging that the second electronic equipment is also in a wide area network connection state, and suggesting wide area network connection with the second electronic equipment; when the device status flag bit is the second value, it is determined that the second electronic device is not in the wan connection state, and S102 is executed, which is not described herein.
In other words, when the first electronic device detects that the first electronic device is in the wide area network connection state and the second electronic device is also in the wide area network connection state, a wide area network connection is established with the second electronic device, and when the first electronic device detects that the first electronic device is not in the wide area network connection state or the second electronic device is not in the wide area network connection state, a local area network connection is established with the second electronic device.
According to the application, the network connection state of the first electronic equipment is detected in real time, the network connection state of the second electronic equipment is further obtained, and the connection state between the first electronic equipment and the second electronic equipment is switched to be local area network connection or wide area network connection, so that good communication and data communication between the first electronic equipment and the second electronic equipment are always kept, the method has good adaptability in a complex working environment, and bad experience brought by disconnection to users is avoided.
In one embodiment, as shown in fig. 7, a network connection method is specifically proposed, which is applied to a server, and which may be implemented by means of a computer program, and may be run on a network connection device based on von neumann system. The computer program may be integrated in the application or may run as a stand-alone tool class application.
S201, monitoring the connection state of the wide area network of the second electronic equipment.
The server and the second electronic device may be connected via a wide area network, as shown in fig. 1. The wide area network connection state of the second electronic device includes the second electronic device being in a wide area network connection state or not being in a wide area network connection state.
In one embodiment, the method for determining the connection state of the wide area network of the second electronic device by the server includes: if the heartbeat signal sent by the second electronic device is not received within the preset time interval, determining that the second electronic device is not in the wide area network connection state. The heartbeat signal can be understood as a method for judging whether the network connection between the interconnected electronic devices has been disconnected by replying to the situation or receiving the situation by sending a small data packet between the electronic devices in a connected state at intervals. The method has high reliability and high detection efficiency.
And S202, when a trigger instruction for communication connection with the second electronic device, which is sent by the first electronic device, is received, the wide area network connection state of the second electronic device is sent to the first electronic device, so that the first electronic device establishes network connection with the second electronic device based on the wide area network connection state of the second electronic device.
When the first electronic equipment receives a trigger instruction for communication connection with the second electronic equipment, the first electronic equipment starts to detect whether the first electronic equipment is in a wide area network connection state or not, and the trigger instruction is sent to a server. The trigger may be any trigger preset or input by a user, such as the trigger shown in fig. 6.
Based on a trigger instruction for communication connection with the second electronic device, the server sends the wide area network connection state of the second electronic device to the first electronic device. For example, the wide area network connection state of the second electronic device of the first electronic device is prompted by sending a device state flag bit to the first electronic device, wherein when the device state flag bit is a first value, the second electronic device is also in the wide area network connection state, and when the device state flag bit is a second value, it is determined that the second electronic device is not in the wide area network connection state.
Therefore, when the first electronic device detects that the first electronic device is in the wide area network connection state and the second electronic device is also in the wide area network connection state, the wide area network connection is established with the second electronic device, and when the first electronic device detects that the first electronic device is not in the wide area network connection state or the second electronic device is not in the wide area network connection state, the local area network connection is established with the second electronic device.
According to the application, the wide area network connection state of the second electronic equipment is sent to the first electronic equipment through the server, so that the first electronic equipment detects the network connection state of the first electronic equipment in real time and further acquires the network connection state of the second electronic equipment, thereby switching the connection state between the first electronic equipment and the second electronic equipment to be local area network connection or wide area network connection, further always keeping good communication and data communication between the first electronic equipment and the second electronic equipment, having good adaptability in a complex working environment, and avoiding the bad experience brought by disconnection to users.
The following are examples of the apparatus of the present application that may be used to perform the method embodiments of the present application. For details not disclosed in the embodiments of the apparatus of the present application, please refer to the embodiments of the method of the present application.
Referring to fig. 8, a schematic structural diagram of a network connection device according to an exemplary embodiment of the present application is shown. The network connection means may be implemented as all or part of the device by software, hardware or a combination of both. The apparatus comprises a first detection module 801, a second detection module 802, a wide area connection module 803 and a local area connection module 804.
A first detection module 801, configured to detect, when a trigger instruction for performing communication connection with a second electronic device is received, whether the first electronic device is in a wide area network connection state;
a second detection module 802, configured to detect whether the second electronic device is in a wide area network connection state if the first electronic device is in a wide area network connection state;
a wide area connection module 803, configured to establish a wide area network connection with the second electronic device if the second electronic device is also in a wide area network connection state;
and the local area connection module 804 is configured to establish a local area network connection with the second electronic device if the second electronic device is not in the wide area network connection state, where the first electronic device and the second electronic device are in the same local area network.
In one embodiment, the first detection module 801 includes:
And the reading mark unit is used for detecting whether the first electronic equipment is in a wide area network connection state or not by reading the numerical value of the network state mark bit of the first electronic equipment.
In one embodiment, the first detection module 801 includes:
the network detection unit is used for changing the numerical value of the network state zone bit of the first electronic equipment when the network detection device of the first electronic equipment detects that the network connection state of the first electronic equipment is changed.
In one embodiment, the second detection module 802 includes:
and the acquisition state unit is used for acquiring the wide area network connection state of the second electronic equipment from the server.
In one embodiment, the acquisition status unit is specifically configured to:
after receiving a first trigger instruction, responding to the first trigger instruction, and sending a request for inquiring the wide area network connection state of the second electronic equipment to the server;
and receiving a wide area network connection state of the second electronic equipment returned by the server.
In one embodiment, the local area connection module 804 includes:
and the local area connection unit is used for establishing local area network connection with the second electronic equipment based on the network interconnection protocol IP address and port information of the second electronic equipment.
In one embodiment, the network connection device further comprises:
and the information acquisition module is used for acquiring the IP address and the port information of the second electronic equipment.
In one embodiment, the information acquisition module includes:
the first acquisition unit is used for receiving the IP address and port information of the second electronic device, which are broadcasted by the second electronic device according to the preset frequency.
In one embodiment, the information acquisition module includes:
and the second acquisition unit is used for responding to the second trigger instruction after receiving the second trigger instruction and acquiring the IP address and port information of the second electronic equipment through a multicast protocol mDNS.
In one embodiment, the information acquisition module includes:
and the third acquisition unit is used for reading the IP address and the port information of the second electronic equipment from the memory of the first electronic equipment.
According to the application, the network connection state of the first electronic equipment is detected in real time, the network connection state of the second electronic equipment is further obtained, and the connection state between the first electronic equipment and the second electronic equipment is switched to be local area network connection or wide area network connection, so that good communication and data communication between the first electronic equipment and the second electronic equipment are always kept, the method has good adaptability in a complex working environment, and bad experience brought by disconnection to users is avoided.
Referring to fig. 9, a schematic diagram of a network connection device according to an exemplary embodiment of the present application is shown. The network connection means may be implemented as all or part of the device by software, hardware or a combination of both. The device comprises a listening connection module 901 and a status transmission module 902.
A monitoring connection module 901, configured to monitor a wide area network connection state of the second electronic device;
the state sending module 902 is configured to send, when receiving a trigger instruction sent by a first electronic device and used for performing communication connection with the second electronic device, a wide area network connection state of the second electronic device to the first electronic device, so that the first electronic device establishes network connection with the second electronic device based on the wide area network connection state of the second electronic device.
In one embodiment, the listening connection module 901 comprises:
and the heartbeat receiving unit is used for determining that the second electronic equipment is not in the wide area network connection state if the heartbeat signal sent by the second electronic equipment is not received within a preset time interval.
According to the application, the wide area network connection state of the second electronic equipment is sent to the first electronic equipment through the server, so that the first electronic equipment detects the network connection state of the first electronic equipment in real time and further acquires the network connection state of the second electronic equipment, thereby switching the connection state between the first electronic equipment and the second electronic equipment to be local area network connection or wide area network connection, further always keeping good communication and data communication between the first electronic equipment and the second electronic equipment, having good adaptability in a complex working environment, and avoiding the bad experience brought by disconnection to users.
It should be noted that, in the network connection device provided in the foregoing embodiment, only the division of the foregoing functional modules is used for illustration when executing the network connection method, and in practical application, the foregoing functional allocation may be performed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules, so as to complete all or part of the functions described above. In addition, the network connection device and the network connection method embodiment provided in the foregoing embodiments belong to the same concept, which represents a detailed implementation process in the method embodiment, and are not described herein again.
The foregoing embodiment numbers of the present application are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
The embodiment of the present application further provides a computer storage medium, where the computer storage medium may store a plurality of instructions, where the instructions are adapted to be loaded by a processor and execute the network connection method according to the embodiment shown in fig. 1 to fig. 6, and the specific execution process may refer to the specific description of the embodiment shown in fig. 1 to fig. 6, which is not repeated herein.
The present application further provides a computer program product, where at least one instruction is stored, where the at least one instruction is loaded by the processor and executed by the processor to implement the network connection method according to the embodiment shown in fig. 1 to fig. 6, and the specific implementation process may refer to the specific description of the embodiment shown in fig. 1 to fig. 6, which is not repeated herein.
Referring to fig. 10, a schematic structural diagram of an electronic device is provided in an embodiment of the present application. As shown in fig. 10, the electronic device 1000 may include: at least one processor 1001, at least one network interface 1004, a user interface 1003, a memory 1005, at least one communication bus 1002.
Wherein the communication bus 1002 is used to enable connected communication between these components.
The user interface 1003 may include a Display screen (Display) and a Camera (Camera), and the optional user interface 1003 may further include a standard wired interface and a wireless interface.
The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface), among others.
Wherein the processor 1001 may include one or more processing cores. The processor 1001 connects various parts within the entire server 1000 using various interfaces and lines, performs various functions of the server 1000 and processes data by executing or executing instructions, programs, code sets, or instruction sets stored in the memory 1005, and calling data stored in the memory 1005. Alternatively, the processor 1001 may be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), programmable logic array (Programmable Logic Array, PLA). The processor 1001 may integrate one or a combination of several of a central processing unit (Central Processing Unit, CPU), an image processor (Graphics Processing Unit, GPU), and a modem, etc. The CPU mainly processes an operating system, a user interface, an application program and the like; the GPU is used for rendering and drawing the content required to be displayed by the display screen; the modem is used to handle wireless communications. It will be appreciated that the modem may not be integrated into the processor 1001 and may be implemented by a single chip.
The Memory 1005 may include a random access Memory (Random Access Memory, RAM) or a Read-Only Memory (Read-Only Memory). Optionally, the memory 1005 includes a non-transitory computer readable medium (non-transitory computer-readable storage medium). The memory 1005 may be used to store instructions, programs, code, sets of codes, or sets of instructions. The memory 1005 may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the above-described respective method embodiments, etc.; the storage data area may store data or the like referred to in the above respective method embodiments. The memory 1005 may also optionally be at least one storage device located remotely from the processor 1001. As shown in fig. 10, an operating system, a network communication module, a user interface module, and a network connection application program may be included in the memory 1005, which is one type of computer storage medium.
In the electronic device 1000 shown in fig. 10, the user interface 1003 is mainly used for providing an input interface for a user, and acquiring data input by the user; the electronic device 1000 is a first electronic device, and the processor 1001 may be configured to invoke a network connection application program stored in the memory 1005, and specifically perform the following operations:
When a trigger instruction for communication connection with second electronic equipment is received, detecting whether the first electronic equipment is in a wide area network connection state;
if the first electronic equipment is in the wide area network connection state, detecting whether the second electronic equipment is in the wide area network connection state;
if the second electronic equipment is also in a wide area network connection state, establishing wide area network connection with the second electronic equipment;
if the second electronic equipment is not in the wide area network connection state, local area network connection is established with the second electronic equipment, and the first electronic equipment and the second electronic equipment are in the same local area network.
In one embodiment, the processor 1001 performs the detecting whether the first electronic device is in a wide area network connection state, specifically performing:
and detecting whether the first electronic equipment is in a wide area network connection state or not by reading the value of the network state zone bit of the first electronic equipment.
In one embodiment, the processor 1001 performs the step of, before reading the value of the network status flag bit and detecting whether the first electronic device is in the wide area network connection state, further performing:
When the network detection device of the first electronic equipment detects that the network connection state of the first electronic equipment is changed, changing the numerical value of the network state zone bit of the first electronic equipment.
In one embodiment, the processor 1001 performs the detecting whether the second electronic device is in the wide area network connection state, specifically performing: and acquiring the wide area network connection state of the second electronic equipment from a server.
In one embodiment, the processor 1001 performs the obtaining, from the server, the wide area network connection status of the second electronic device, specifically performing:
after receiving a first trigger instruction, responding to the first trigger instruction, and sending a request for inquiring the wide area network connection state of the second electronic equipment to the server;
and receiving a wide area network connection state of the second electronic equipment returned by the server.
In one embodiment, the processor 1001 performs the establishing a local area network connection with the second electronic device, specifically performs: and establishing local area network connection with the second electronic equipment based on the network interconnection protocol IP address and port information of the second electronic equipment.
In one embodiment, before the processor 1001 performs the establishing a local area network connection with the second electronic device, the method further performs: and acquiring the IP address and port information of the second electronic equipment.
In one embodiment, the processor 1001 performs the obtaining the IP address and port information of the second electronic device, specifically performs:
and receiving the IP address and port information of the second electronic equipment, which are broadcasted by the second electronic equipment according to the preset frequency.
In one embodiment, the processor 1001 performs the obtaining the IP address and port information of the second electronic device, specifically performs:
after receiving a second trigger instruction, responding to the second trigger instruction, and acquiring the IP address and port information of the second electronic equipment through a multicast protocol mDNS.
In one embodiment, the processor 1001 performs the obtaining the IP address and port information of the second electronic device, specifically performs: and reading the IP address and port information of the second electronic device from the memory of the first electronic device.
In one embodiment, the electronic device 1000 is a server, and the processor 1001 may be further configured to invoke a network connection application program stored in the memory 1005, and specifically perform the following operations:
monitoring the connection state of the wide area network of the second electronic equipment;
when a trigger instruction of communication connection with the second electronic device, which is sent by the first electronic device, is received, the wide area network connection state of the second electronic device is sent to the first electronic device, so that the first electronic device establishes network connection with the second electronic device based on the wide area network connection state of the second electronic device.
In one embodiment, the processor 1001 performs the monitoring of the wide area network connection status of the second electronic device, specifically performs:
and if the heartbeat signal sent by the second electronic equipment is not received within a preset time interval, determining that the second electronic equipment is not in a wide area network connection state.
According to the application, the network connection state of the first electronic equipment is detected in real time, the network connection state of the second electronic equipment is further obtained, and the connection state between the first electronic equipment and the second electronic equipment is switched to be local area network connection or wide area network connection, so that good communication and data communication between the first electronic equipment and the second electronic equipment are always kept, the method has good adaptability in a complex working environment, and bad experience brought by disconnection to users is avoided.
Those skilled in the art will appreciate that implementing all or part of the above-described methods in accordance with the embodiments may be accomplished by way of a computer program stored on a computer readable storage medium, which when executed may comprise the steps of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a read-only memory, a random access memory, or the like.
The foregoing disclosure is illustrative of the present application and is not to be construed as limiting the scope of the application, which is defined by the appended claims.
Claims (15)
1. A method of network connection, the method being applied to a first electronic device, the method comprising:
when a trigger instruction for communication connection with second electronic equipment is received, detecting whether the first electronic equipment is in a wide area network connection state;
if the first electronic equipment is in the wide area network connection state, detecting whether the second electronic equipment is in the wide area network connection state;
if the second electronic equipment is also in a wide area network connection state, establishing wide area network connection with the second electronic equipment;
if the second electronic equipment is not in the wide area network connection state, local area network connection is established with the second electronic equipment, and the first electronic equipment and the second electronic equipment are in the same local area network.
2. The method of claim 1, wherein the detecting whether the first electronic device is in a wide area network connected state comprises:
And detecting whether the first electronic equipment is in a wide area network connection state or not by reading the value of the network state zone bit of the first electronic equipment.
3. The method according to claim 2, wherein before detecting whether the first electronic device is in the wide area network connection state by reading the value of the network status flag bit, further comprises:
when the network detection device of the first electronic equipment detects that the network connection state of the first electronic equipment is changed, changing the numerical value of the network state zone bit of the first electronic equipment.
4. The method of claim 1, wherein the detecting whether the second electronic device is in a wide area network connected state comprises: and acquiring the wide area network connection state of the second electronic equipment from a server.
5. The method of claim 4, wherein the obtaining the wide area network connection status of the second electronic device from the server comprises:
after receiving a first trigger instruction, responding to the first trigger instruction, and sending a request for inquiring the wide area network connection state of the second electronic equipment to the server;
And receiving a wide area network connection state of the second electronic equipment returned by the server.
6. The method of claim 1, wherein the establishing a local area network connection with the second electronic device comprises: and establishing local area network connection with the second electronic equipment based on the network interconnection protocol IP address and port information of the second electronic equipment.
7. The method of any of claims 1-6, wherein prior to establishing a local area network connection with the second electronic device, further comprising: and acquiring the IP address and port information of the second electronic equipment.
8. The method of claim 7, wherein the obtaining the IP address and port information of the second electronic device comprises:
and receiving the IP address and port information of the second electronic equipment, which are broadcasted by the second electronic equipment according to the preset frequency.
9. The method of claim 7, wherein the obtaining the IP address and port information of the second electronic device comprises:
after receiving a second trigger instruction, responding to the second trigger instruction, and acquiring the IP address and port information of the second electronic equipment through a multicast protocol mDNS.
10. The method of claim 7, wherein the obtaining the IP address and port information of the second electronic device comprises: and reading the IP address and port information of the second electronic device from the memory of the first electronic device.
11. A network connection method, wherein the method is applied to a server, the method comprising:
monitoring the connection state of the wide area network of the second electronic equipment;
when a trigger instruction of communication connection with the second electronic device, which is sent by the first electronic device, is received, the wide area network connection state of the second electronic device is sent to the first electronic device, so that the first electronic device establishes network connection with the second electronic device based on the wide area network connection state of the second electronic device.
12. The method of claim 11, wherein listening for a wide area network connection status of the second electronic device comprises:
and if the heartbeat signal sent by the second electronic equipment is not received within a preset time interval, determining that the second electronic equipment is not in a wide area network connection state.
13. A network connection device, the device comprising:
The first detection module is used for detecting whether the first electronic equipment is in a wide area network connection state or not when a trigger instruction for communication connection with the second electronic equipment is received;
the second detection module is used for detecting whether the second electronic equipment is in a wide area network connection state or not if the first electronic equipment is in the wide area network connection state;
the wide area connection module is used for establishing wide area network connection with the second electronic equipment if the second electronic equipment is also in a wide area network connection state;
and the local area connection module is used for establishing local area network connection with the second electronic equipment if the second electronic equipment is not in a wide area network connection state, and the first electronic equipment and the second electronic equipment are in the same local area network.
14. A network connection device, the device comprising:
the monitoring connection module is used for monitoring the wide area network connection state of the second electronic equipment;
and the state sending module is used for sending the wide area network connection state of the second electronic equipment to the first electronic equipment when receiving a trigger instruction which is sent by the first electronic equipment and is used for carrying out communication connection with the second electronic equipment, so that the first electronic equipment establishes network connection with the second electronic equipment based on the wide area network connection state of the second electronic equipment.
15. An electronic device, comprising: a processor and a memory; wherein the memory stores a computer program adapted to be loaded by the processor and to perform the method steps of any of claims 1-12.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210278519.0A CN116828030A (en) | 2022-03-21 | 2022-03-21 | Network connection method, device, storage medium and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210278519.0A CN116828030A (en) | 2022-03-21 | 2022-03-21 | Network connection method, device, storage medium and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116828030A true CN116828030A (en) | 2023-09-29 |
Family
ID=88113245
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210278519.0A Pending CN116828030A (en) | 2022-03-21 | 2022-03-21 | Network connection method, device, storage medium and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116828030A (en) |
-
2022
- 2022-03-21 CN CN202210278519.0A patent/CN116828030A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110417915B (en) | Push message transmission method and device, storage medium and electronic equipment | |
EP4236463A2 (en) | Method for supporting both voice service and data service and terminal | |
CN107634962B (en) | Network bandwidth management method and related products | |
WO2014206194A1 (en) | Message notification method,system,and device for a communication account | |
US20230066942A1 (en) | Information transmission method and apparatus, and electronic device | |
CN103619067B (en) | Wireless channel redistribution method and device | |
CN110856103B (en) | Scheduling method, communication method and related equipment | |
CN107347011B (en) | Group message processing method, equipment and computer readable storage medium | |
CN109246315B (en) | Incoming call processing method in online game process, mobile terminal and readable storage medium | |
US20220053585A1 (en) | Method for pc5 link establishment, device, and system | |
CN112689191A (en) | Screen projection control method, terminal and computer readable storage medium | |
CN109495769B (en) | Video communication method, terminal, smart television, server and storage medium | |
US8456671B2 (en) | Communication system, information storage device, management device, and terminal device | |
CN112492340B (en) | Live broadcast audio acquisition method, mobile terminal and computer readable storage medium | |
WO2022183550A1 (en) | Network switching method, storage medium, and gateway device | |
CN116828030A (en) | Network connection method, device, storage medium and electronic equipment | |
CN114126083B (en) | Cross-network-segment wireless screen projection method and device, electronic equipment and storage medium | |
CN107404425A (en) | The notification message reminding method and terminal of terminal room | |
US11784900B2 (en) | Using wireless packets to indicate device boot status | |
CN115665713A (en) | Multi-device communication method, device, equipment and storage medium | |
CN113485667A (en) | Method for screen projection display of terminal, terminal and storage medium | |
CN108650403B (en) | Message sending method, mobile terminal and server | |
CN110971756A (en) | Communication method, communication device, computer readable storage medium and terminal | |
CN112888056B (en) | Picture processing method, system, computer equipment and storage medium of electronic price tag | |
CN110213319B (en) | Access method and device, terminal, server and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |