CN114650315A - Method for establishing long connection between client and server - Google Patents

Method for establishing long connection between client and server Download PDF

Info

Publication number
CN114650315A
CN114650315A CN202210142246.7A CN202210142246A CN114650315A CN 114650315 A CN114650315 A CN 114650315A CN 202210142246 A CN202210142246 A CN 202210142246A CN 114650315 A CN114650315 A CN 114650315A
Authority
CN
China
Prior art keywords
long connection
client
server
time interval
heartbeat
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.)
Withdrawn
Application number
CN202210142246.7A
Other languages
Chinese (zh)
Inventor
王永亮
任启红
黄辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sanjiang University
Original Assignee
Sanjiang University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sanjiang University filed Critical Sanjiang University
Priority to CN202210142246.7A priority Critical patent/CN114650315A/en
Publication of CN114650315A publication Critical patent/CN114650315A/en
Withdrawn legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/143Termination or inactivation of sessions, e.g. event-controlled end of session
    • H04L67/145Termination or inactivation of sessions, e.g. event-controlled end of session avoiding end of session, e.g. keep-alive, heartbeats, resumption message or wake-up for inactive or interrupted session

Landscapes

  • Health & Medical Sciences (AREA)
  • Cardiology (AREA)
  • General Health & Medical Sciences (AREA)
  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses a method for establishing long connection between a client and a server, which comprises the following steps: receiving a long connection request sent by a client; establishing a first long connection and a second long connection between the client and the server based on the response of the server to the long connection request; transmitting a message between the client and the server by using the first long connection, and searching for an optimal heartbeat time interval by using the second long connection; when the optimal heartbeat time interval is found, any long connection maintains the long connection at the optimal heartbeat time interval, transmits the message and actively disconnects another long connection at the same time. In the process of establishing the long connection between the client and the server, the method separates the connection used by the optimal heartbeat searching from the connection used by the message transmission, can always keep the smoothness of a message transmission channel in the process of searching the optimal heartbeat interval, and cannot be disconnected due to the heartbeat searching process, thereby ensuring the timeliness of the information transmission between the client and the server.

Description

Method for establishing long connection between client and server
Technical Field
The invention relates to the field of internet communication, in particular to a method for establishing long connection between a client and a server.
Background
When the server and the client communicate with each other over the network, long connection needs to be maintained frequently, and especially when the server needs to actively push messages to the client, the long connection can ensure that the client or the server can send messages to the other side in time. In the process of maintaining a long connection, since an intermediate network device, such as a device with a firewall function, is limited by its air interface time, it is generally required that the client and the server maintain the long connection by sending heartbeat information at an interval when no message is sent. In order to send heartbeat information, an optimal heartbeat information sending interval needs to be found out, so that long connection is ensured not to be disconnected, and resources such as too much traffic and the like are not consumed.
In the long connection setup process, finding the optimal heartbeat may be involved. The existing optimal heartbeat finding procedure generally includes: the client and the server need to establish a long connection first, then send the heartbeat from small to large or from large to small according to the time interval, if the long connection can be maintained by sending the heartbeat information when the time interval is used as n, then send the heartbeat information by using the time interval of n +1 or n-1, and if the long connection is disconnected, the optimal heartbeat interval is determined as n. In the long connection establishing process, at least one time of long connection disconnection occurs on the aspect of finding the optimal heartbeat interval time, and if the long connection between the server and the client is disconnected, the timely communication between the server and the client is influenced.
Disclosure of Invention
The purpose of the invention is as follows: in view of the above problems, the present invention aims to provide a long connection establishment method for a client and a server, which can maintain the long connection established between the client and the server without interruption by establishing two long connections.
The technical scheme is as follows: the invention discloses a method for establishing long connection between a client and a server, which comprises the following steps:
s10, receiving a long connection request sent by a client;
s20, establishing a first long connection and a second long connection between the client and the server based on the response of the server to the long connection request;
s30, transmitting the message between the client and the server by using the first long connection, and searching the optimal heartbeat time interval by using the second long connection;
and S40, after finding the optimal heartbeat time interval, maintaining the long connection at the optimal heartbeat time interval by any long connection, transmitting the message, and actively disconnecting the other long connection.
Further, when the first long connection transmits the message between the client and the server, the heartbeat information is sent according to the minimum heartbeat time interval.
Has the advantages that: compared with the prior art, the invention has the following remarkable advantages: in the process of establishing long connection between the client and the server, the connection used by the optimal heartbeat search and the connection used by message transmission are separated, and in the process of searching the optimal heartbeat interval, the smoothness of a message transmission channel can be always kept and the disconnection caused by the heartbeat search process can be avoided, so that the timeliness of information transmission between the client and the server is ensured; meanwhile, only heartbeat information exists in a connecting channel for heartbeat searching, so that the interference of common information in the heartbeat searching process is avoided, and the accuracy of searching the optimal heartbeat interval is ensured; only two long connections are established, and the flow resource is saved.
Drawings
Fig. 1 is a flow chart of a long connection establishment method of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments.
Example 1
In this embodiment, it is assumed that the optimal heartbeat time interval between the client and the server is 2 minutes, and the minimum heartbeat time interval is 1 minute due to service limitation.
As shown in fig. 1, the method for establishing a long connection between a client and a server according to this embodiment includes the following steps:
s10, receiving a long connection request sent by a client;
s20, establishing a first long connection and a second long connection between the client and the server based on the response of the server to the long connection request;
s30, transmitting the message between the client and the server by using the first long connection, and searching the optimal heartbeat time interval by using the second long connection;
in order to ensure that the network disconnection does not occur due to the air interface time of the network equipment, when the message between the client and the server is transmitted through the first long connection, the heartbeat information is sent according to the time interval of 1 minute.
Finding the optimal heartbeat time interval using the second long connection comprises:
starting to send heartbeat detection from the minimum heartbeat time interval, and sending heartbeats at 1 minute intervals at first; after 1 minute, the second long connection is not disconnected, and heartbeat information of 2 minute intervals is sent; after 2 minutes, the second long connection is not disconnected, and heartbeat information of 3-minute intervals starts to be sent; after 3 minutes, the second long connection is broken, and the optimal heartbeat time interval is determined to be 2 minutes.
And S40, when the optimal heartbeat time interval is found, the first long connection sends heartbeat information by using the optimal heartbeat time interval and continues to be used as a message transmission channel.
And when the optimal heartbeat time interval is determined to be 2 minutes, the first long connection uses 2 minutes to send heartbeat information and continues to be used as a message transmission channel.
Example 2
In this embodiment, it is assumed that the optimal heartbeat time interval between the client and the server is 2 minutes, and the minimum heartbeat time interval is 1 minute due to service limitation.
The method for establishing the long connection between the client and the server comprises the following steps:
s10, receiving a long connection request sent by a client;
s20, establishing a first long connection and a second long connection between the client and the server based on the response of the server to the long connection request;
s30, transmitting the message between the client and the server by using the first long connection, and searching the optimal heartbeat time interval by using the second long connection;
when the first long connection transmits the message between the client and the server, the heartbeat information is sent at intervals of 1 minute.
Finding the optimal heartbeat time interval using the second long connection comprises:
starting to send heartbeat detection from the minimum heartbeat time interval, and sending heartbeats at an interval of 1 minute at first; after 1 minute, the second long connection is not disconnected, and heartbeat information of 2 minute intervals is sent; after 2 minutes, the second long connection is not disconnected, and heartbeat information of 3-minute intervals starts to be sent; after 3 minutes, the second long connection is broken, and the optimal heartbeat time interval is determined to be 2 minutes.
And S40, when the optimal heartbeat time interval is found, the second long connection sends heartbeat information by using the optimal heartbeat time interval, continues to be used as a message transmission channel, and actively disconnects the first long connection.
And after the optimal heartbeat time interval is determined to be 2 minutes, reestablishing the second long connection as a message transmission channel, sending heartbeat information by using the second long connection for 2 minutes, and actively disconnecting the first long connection.

Claims (2)

1. A method for establishing long connection between a client and a server is characterized by comprising the following steps:
s10, receiving a long connection request sent by a client;
s20, establishing a first long connection and a second long connection between the client and the server based on the response of the server to the long connection request;
s30, transmitting the message between the client and the server by using the first long connection, and searching the optimal heartbeat time interval by using the second long connection;
and S40, after finding the optimal heartbeat time interval, any long connection maintains the long connection at the optimal heartbeat time interval, and transmits a message, and simultaneously actively disconnects another long connection.
2. The long connection setup method according to claim 1, wherein the heartbeat information is sent at a minimum heartbeat time interval when the first long connection transmits a message between the client and the server.
CN202210142246.7A 2022-02-16 2022-02-16 Method for establishing long connection between client and server Withdrawn CN114650315A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210142246.7A CN114650315A (en) 2022-02-16 2022-02-16 Method for establishing long connection between client and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210142246.7A CN114650315A (en) 2022-02-16 2022-02-16 Method for establishing long connection between client and server

Publications (1)

Publication Number Publication Date
CN114650315A true CN114650315A (en) 2022-06-21

Family

ID=81993518

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210142246.7A Withdrawn CN114650315A (en) 2022-02-16 2022-02-16 Method for establishing long connection between client and server

Country Status (1)

Country Link
CN (1) CN114650315A (en)

Similar Documents

Publication Publication Date Title
CN102027711B (en) The method and apparatus of multicast fabric anomaly
CN104812094A (en) Method and apparatus for establishing connection between devices
US10666769B2 (en) Network system and method for establishing data link by using relay node
WO2022042146A9 (en) Communication method and device
US20080071914A1 (en) Session control system
KR100609738B1 (en) Peer-to-peer communication system
CN105072149A (en) Method and device for building remote communication through proxy gateway
US9350606B2 (en) System and method for assigning server to terminal and efficiently delivering messages to the terminal
CN108337241B (en) Multimedia data transmission method and system
CN114650315A (en) Method for establishing long connection between client and server
CN109936603B (en) Non-direct connection network communication method based on HTTP
CN112311759B (en) Equipment connection switching method and system under hybrid network
CN109379443B (en) Method for realizing distributed message queue facing to Internet of things
CN110474781B (en) Method and device for forwarding multicast data
JP6255730B2 (en) Wireless communication system, location registration method, relay device, and wireless terminal device
CN107548025B (en) Position information sharing method and core network
WO2016183730A1 (en) Data transmission method and apparatus
CN112600894A (en) Non-polling-based vehicle real-time fault alarm pushing system and pushing method
CN111542098A (en) Communication connection method of ZigBee device and related device
CN104580490B (en) Order transmission method and device
CN113381990B (en) Method and system for intercommunication between on-demand terminals
CN114374453B (en) Emergency broadcasting multi-terminal audio synchronization method and emergency broadcasting system
CN110932874B (en) Distributed message broadcast notification implementation method
CN105072150A (en) Service call method, and service call method and device through proxy gateway
CN116800816A (en) Method for managing large number of long connections between server and client

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
WW01 Invention patent application withdrawn after publication

Application publication date: 20220621

WW01 Invention patent application withdrawn after publication