CN107734001B - Method for judging whether communication is disconnected or not based on timing asynchronous communication mechanism - Google Patents
Method for judging whether communication is disconnected or not based on timing asynchronous communication mechanism Download PDFInfo
- Publication number
- CN107734001B CN107734001B CN201710874741.6A CN201710874741A CN107734001B CN 107734001 B CN107734001 B CN 107734001B CN 201710874741 A CN201710874741 A CN 201710874741A CN 107734001 B CN107734001 B CN 107734001B
- Authority
- CN
- China
- Prior art keywords
- browser
- variable
- disconnected
- timer
- embedded 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.)
- Active
Links
Images
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/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
-
- 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/08—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
- H04L43/0805—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
- H04L43/0811—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking connectivity
-
- 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/01—Protocols
- H04L67/08—Protocols specially adapted for terminal emulation, e.g. Telnet
Abstract
The invention relates to computer network communication, in particular to a method for judging whether communication is disconnected based on a timing asynchronous communication mechanism, which is characterized in that on the basis of a 1-second timer for communication between a system and an embedded device and a 2-second timer for quitting an overtime callback, a method with lower consumption is used, after the embedded device is disconnected from communication, a JavaScript program of a browser on terminal equipment can also recognize that the specific consumption adds a variable for a JavaScript end acquisition result of the browser, adds a global variable, adds a comparison branch in a 2-second timer processing function, adds a judgment branch with two variables in total, and does not need to add a large frame to realize the function; the technical scheme provided by the invention can effectively overcome the defect that the embedded equipment is blocked because the user does not sense that the network connection between the terminal equipment and the embedded equipment is disconnected and continues to operate in the prior art.
Description
Technical Field
The invention relates to computer network communication, in particular to a method for judging whether communication is disconnected or not based on a timing asynchronous communication mechanism.
Background
Most embedded devices are controlled and managed remotely via the Web. Specifically, the terminal is connected to the embedded device through a network cable, wifi or other means, an IP address of the embedded device is input into a browser of the terminal, webpage information is loaded, and after login, state viewing and configuration management of the embedded device can be performed, as shown in fig. 2.
HTML is some web page controls, JavaScript is a script language, and the source code of the HTML is not compiled before being sent to a client side to be operated, but character codes in a text format are sent to a browser to be interpreted and operated by the browser, so that dynamic functions are added to the HTML web page. CSS provides a style description for the HTML markup language that defines the way elements are displayed therein.
Ajax uses asynchronous data transfer (HTTP request) between the browser and the embedded device Web service, which allows the Web page to request a small amount of information from the embedded device, rather than the entire page. Techniques that enable partial web pages to be updated without reloading the entire web page. Ajax can make the webpage program smaller, faster and more friendly.
JSON can convert a set of data represented in a JavaScript object into a string, and then can easily transfer the string between networks or programs and restore it to a data format supported by each programming language when necessary. jQuery is a fast, compact JavaScript framework.
Disclosure of Invention
Technical problem to be solved
Aiming at the defects in the prior art, the invention provides a method for judging whether communication is disconnected or not based on a timing asynchronous communication mechanism, which can effectively overcome the defect that the embedded equipment is blocked because a user does not sense that the network connection between the terminal equipment and the embedded equipment is disconnected and continues to operate in the prior art.
(II) technical scheme
In order to achieve the purpose, the invention is realized by the following technical scheme:
a method for judging whether communication is disconnected or not based on a timing asynchronous communication mechanism comprises the following steps:
s1, when a user logs in the embedded device through the Web browser, the browser script starts a 1-second timer;
s2, asynchronously sending GET information of HTTP protocol to Web service program in embedded device;
s3, after receiving the message, the Web service program in the embedded device reads the information in the database and feeds the information back to the browser by adopting a JSON format;
s4, after acquiring the feedback result of the embedded device, the browser script refers to a jQuery library to analyze the value type and converts the value type into an object timerInfo;
s5, adding a variable in the timerInfo object, assigning a random number to the variable, and setting the initial value of the variable to be 0;
s6, after a user inputs a password on the Web browser to log in the embedded equipment, the browser script starts a 2-second timer for detecting the logging and connection conditions of the embedded equipment;
s7, if the user does not operate the page for a period of time, the connection between the browser and the embedded device is automatically finished, and the user needs to input the password again for logging in;
s8, newly defining a global variable for recording the random number generated last time by the 1 second timer, wherein the initial value of the global variable is 0;
s9, in the 2-second timer program, comparing the random value of the global variable with the random value of the variable in the timerInfo object, if the random values are the same, judging that the communication connection is disconnected, giving a prompt that the embedded device is disconnected by the page, if the random values are different, assigning the random number in the current variable to the global variable, and continuing the circular processing.
Preferably, the browser script is a JavaScript program.
Preferably, the GET message of the asynchronous transmission HTTP protocol is transmitted through an Ajax program.
Preferably, after receiving the message, the Web service program in the embedded device reads the value of the database and feeds the value back to the browser in the JSON format.
Preferably, the variable is named hearstBeatNum.
Preferably, the global variable is named lastheartbacknum.
(III) advantageous effects
Compared with the prior art, the method for judging whether the communication is disconnected based on the timing asynchronous communication mechanism provided by the invention has the advantages that on the basis of the existing 1-second timer for communication between the timing asynchronous communication mechanism and the embedded equipment and the existing 2-second timer for overtime callback quitting, the JavaScript program of the browser on the terminal equipment can be identified by using a method with lower consumption after the embedded equipment is disconnected from the communication. The specific consumption is that a variable is added to a JavaScript end acquisition result of the browser, a global variable is added, a comparison branch is added to a 2-second timer processing function, two variables and a judgment branch are added in total, and a large frame is not required to be added to realize the function.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below. It is obvious that the drawings in the following description are only some embodiments of the invention, and that for a person skilled in the art, other drawings can be derived from them without inventive effort.
FIG. 1 is a schematic flow chart of the present invention;
fig. 2 is a schematic diagram of a basic structure of a system for remotely controlling and managing an embedded device by Web.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention. It is to be understood that the embodiments described are only a few embodiments of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
A method for determining whether communication is disconnected based on a timed asynchronous communication mechanism, as shown in fig. 1, includes the following steps:
s1, when a user logs in the embedded device through the Web browser, the browser script starts a 1-second timer;
s2, asynchronously sending GET information of HTTP protocol to Web service program in embedded device;
s3, after receiving the message, the Web service program in the embedded device reads the information in the database and feeds the information back to the browser by adopting a JSON format;
s4, after acquiring the feedback result of the embedded device, the browser script refers to a jQuery library to analyze the value type and converts the value type into an object timerInfo;
s5, adding a variable in the timerInfo object, assigning a random number to the variable, and setting the initial value of the variable to be 0;
s6, after a user inputs a password on the Web browser to log in the embedded equipment, the browser script starts a 2-second timer for detecting the logging and connection conditions of the embedded equipment;
s7, if the user does not operate the page for a period of time, the connection between the browser and the embedded device is automatically finished, and the user needs to input the password again for logging in;
s8, newly defining a global variable for recording the random number generated last time by the 1 second timer, wherein the initial value of the global variable is 0;
s9, in the 2-second timer program, comparing the random value of the global variable with the random value of the variable in the timerInfo object, if the random values are the same, judging that the communication connection is disconnected, giving a prompt that the embedded device is disconnected by the page, if the random values are different, giving the global variable the random value of the variable in the timerInfo object, and continuing the circulation processing.
The browser script is a JavaScript program, GET messages of an HTTP protocol are asynchronously sent through an Ajax program, after a Web service program in the embedded equipment receives the GET messages, values of a database are read and fed back to the browser in a JSON format, a variable is named as heartTatNum, and a global variable is named as lastHeartTatNum.
After a browser of the terminal equipment logs in an IP page of the embedded equipment, a JavaScript program of the browser starts a 1-second timer, and GET information of an HTTP protocol is asynchronously sent to a Web service program in the embedded equipment through Ajax. And after receiving the message, the Web service program in the embedded equipment reads the value in the database and feeds the value back to the browser in a JSON format. Completing the timing asynchronous communication between the two communication units.
After acquiring a feedback result of the embedded device, the browser JavaScript program Ajax refers to a jQuery library to analyze a JSON data type, converts the JSON data type into an object timerInfo in JavaScript, adds a variable heartbeat Num in the timerInfo object and assigns a random value to the variable heartbeat Num, and specifically comprises the following steps:
timerInfo.heartBeatNum=Math.random();
after the browser inputs a password to log in the embedded device, a JavaScript program of the browser starts a 2-second timer for detecting the login and connection conditions of the embedded device, so that prompt is conveniently given, and the user can safely and conveniently use the embedded device. From the view point of random time triggering of the timer, the upper 1 second timer of the 2 second timer in the time window is executed once, so that the accurate guarantee of state comparison is ensured in the time sequence.
A new global variable lastheartbacknum is defined to record the last generated random number of the 1 second timer, and the initial value of this variable is 0. The method specifically comprises the following steps:
var lastHeartBeatNum=0;
in the execution program of the 2-second timer, comparing the last random value lastheartbeat num with the current random value heartbeat num, specifically:
If(lastHeartBeatNum=info.heartBeatNum){
showAlert('need_reconnect_again');
return;
}
else{
lastHeartBeatNum=info.heartBeatNum;
}
as can be seen from the above procedure, if the same is true, the random number is not updated within 1 second, the connection is considered to be disconnected, and a prompt is given back. If not, lastHeartBeatNum is updated for the next decision.
The method for judging whether the communication is disconnected or not based on the timing asynchronous communication mechanism provided by the invention uses a method with lower consumption on the basis of the existing 1-second timer for communication between the timing asynchronous communication and the embedded equipment and the timer for quitting the 2-second timer for overtime callback of the system, so that the JavaScript program of the browser on the terminal equipment can be identified after the embedded equipment is disconnected from the communication. The specific consumption is that a variable is added to a JavaScript end acquisition result of the browser, a global variable is added, a comparison branch is added to a 2-second timer processing function, two variables and a judgment branch are added in total, and a large frame is not required to be added to realize the function.
The above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit and scope of the corresponding technical solutions.
Claims (6)
1. A method for judging whether communication is disconnected based on a timing asynchronous communication mechanism is characterized in that: the method comprises the following steps:
s1, when a user logs in the embedded device through the Web browser, the browser script starts a 1-second timer;
s2, asynchronously sending GET information of HTTP protocol to Web service program in embedded device;
s3, after receiving the message, the Web service program in the embedded device reads the information in the database and feeds the information back to the browser by adopting a JSON format;
s4, after acquiring the feedback result of the embedded device, the browser script refers to a jQuery library to analyze the value type and converts the value type into an object timerInfo;
s5, adding a variable in the timerInfo object, assigning a random number to the variable, and setting the initial value of the variable to be 0;
s6, after a user inputs a password on the Web browser to log in the embedded equipment, the browser script starts a 2-second timer for detecting the logging and connection conditions of the embedded equipment;
s7, if the user does not operate the page for a period of time, the connection between the browser and the embedded device is automatically finished, and the user needs to input the password again for logging in;
s8, newly defining a global variable for recording the random number generated last time by the 1 second timer, wherein the initial value of the global variable is 0;
s9, in the 2-second timer program, comparing the random value of the global variable with the random value of the variable in the timerInfo object, if the random values are the same, judging that the communication connection is disconnected, giving a prompt that the embedded device is disconnected by the page, if the random values are different, assigning the random number in the current variable to the global variable, and continuing the circular processing.
2. The method for determining whether communication is disconnected based on the timed asynchronous communication mechanism as claimed in claim 1, wherein: the browser script would be a JavaScript program.
3. The method for determining whether communication is disconnected based on the timed asynchronous communication mechanism as claimed in claim 1, wherein: the GET message of the asynchronous transmission HTTP protocol is transmitted through the Ajax program.
4. The method for determining whether communication is disconnected based on the timed asynchronous communication mechanism as claimed in claim 1, wherein: and after receiving the message, the Web service program in the embedded equipment reads the value of the database and feeds the value back to the browser in a JSON format.
5. The method for determining whether communication is disconnected based on the timed asynchronous communication mechanism as claimed in claim 1, wherein: the variable is named heartbeat num.
6. The method for determining whether communication is disconnected based on the timed asynchronous communication mechanism as claimed in claim 1, wherein: the global variable is named lastheaartbacknum.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710874741.6A CN107734001B (en) | 2017-09-25 | 2017-09-25 | Method for judging whether communication is disconnected or not based on timing asynchronous communication mechanism |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710874741.6A CN107734001B (en) | 2017-09-25 | 2017-09-25 | Method for judging whether communication is disconnected or not based on timing asynchronous communication mechanism |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107734001A CN107734001A (en) | 2018-02-23 |
CN107734001B true CN107734001B (en) | 2020-05-15 |
Family
ID=61206857
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710874741.6A Active CN107734001B (en) | 2017-09-25 | 2017-09-25 | Method for judging whether communication is disconnected or not based on timing asynchronous communication mechanism |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107734001B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112866057B (en) * | 2021-01-11 | 2023-03-10 | 北京科技大学设计研究院有限公司 | Method for determining a communication disconnection between a transmission and an automation controller in a Profinet network |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106254179A (en) * | 2016-08-05 | 2016-12-21 | 深圳先进技术研究院 | A kind of heartbeat packet asynchronous controlling method and device |
WO2016205402A1 (en) * | 2015-06-16 | 2016-12-22 | Google, Inc. | Remote alarm hushing |
EP3169038A1 (en) * | 2015-11-12 | 2017-05-17 | Genband US LLC | Asynchronous collaboration session linked to a synchronous collaboration session |
-
2017
- 2017-09-25 CN CN201710874741.6A patent/CN107734001B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2016205402A1 (en) * | 2015-06-16 | 2016-12-22 | Google, Inc. | Remote alarm hushing |
EP3169038A1 (en) * | 2015-11-12 | 2017-05-17 | Genband US LLC | Asynchronous collaboration session linked to a synchronous collaboration session |
CN106254179A (en) * | 2016-08-05 | 2016-12-21 | 深圳先进技术研究院 | A kind of heartbeat packet asynchronous controlling method and device |
Non-Patent Citations (1)
Title |
---|
基于AJAX、Web Service和SIP协议的异步通信机制研究;徐伟;《科技资讯》;20170531;第15卷(第5期);21-22,24 * |
Also Published As
Publication number | Publication date |
---|---|
CN107734001A (en) | 2018-02-23 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10277697B2 (en) | Method and system for pushing web application message | |
US10356487B2 (en) | Video advertisement filtering method, apparatus and device | |
CN107528858B (en) | Login method, device and equipment based on webpage and storage medium | |
CN108874810B (en) | Information acquisition method and device | |
CN107508720B (en) | Automatic testing method and device | |
CN103577187A (en) | Method and related equipment for realizing webpage screenshot | |
CN102752371B (en) | In client, realize method and the client of dodging screen | |
CN105812406B (en) | Information transferring method and device based on WEB emulation terminal system | |
CN112437047A (en) | Remote server management method, system and related device | |
US20160380959A1 (en) | Communication message consolidation with content difference fomatting | |
CN103605689A (en) | Method and device for acquiring visiting staying time | |
CN108632361A (en) | A kind of webpage loading method, server, system and storage medium | |
CN107734001B (en) | Method for judging whether communication is disconnected or not based on timing asynchronous communication mechanism | |
CN101707627A (en) | Method and device for presenting page information | |
CN105530232B (en) | Account login method and device | |
CN103942307A (en) | Leading-end acceleration method based on picture stream | |
US20170060112A1 (en) | Control program for accessing browser data and for controlling appliance | |
CN103220170B (en) | Method and device for automatically configuring and managing equipment | |
US10257032B2 (en) | User guidance data for establishing a desired end-state configuration | |
CN105893502A (en) | Code synchronization method and device | |
KR101863745B1 (en) | Fire engine pump monitoring and control system using web server and the method thereof | |
CN108989404A (en) | A kind of barrage message issuing method, server, system and storage medium | |
CN110688282B (en) | Webpage performance data monitoring and monitoring task distribution method and device | |
CN106777055A (en) | It is a kind of to realize the method and apparatus that website interface is rendered | |
CN103826154A (en) | Routing attribute setting method, digital television receiving terminal and routing server |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |