CN110365803B - Network channel maintaining method based on UDP protocol - Google Patents

Network channel maintaining method based on UDP protocol Download PDF

Info

Publication number
CN110365803B
CN110365803B CN201910790340.1A CN201910790340A CN110365803B CN 110365803 B CN110365803 B CN 110365803B CN 201910790340 A CN201910790340 A CN 201910790340A CN 110365803 B CN110365803 B CN 110365803B
Authority
CN
China
Prior art keywords
server
terminal equipment
data packet
heartbeat
registration
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
Application number
CN201910790340.1A
Other languages
Chinese (zh)
Other versions
CN110365803A (en
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.)
Sichuan Etherbas Technology Development Co ltd
Original Assignee
Sichuan Etherbas Technology Development Co ltd
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 Sichuan Etherbas Technology Development Co ltd filed Critical Sichuan Etherbas Technology Development Co ltd
Priority to CN201910790340.1A priority Critical patent/CN110365803B/en
Publication of CN110365803A publication Critical patent/CN110365803A/en
Application granted granted Critical
Publication of CN110365803B publication Critical patent/CN110365803B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/1066Session management
    • H04L65/1073Registration or de-registration
    • 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/141Setup of application sessions
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/54Presence management, e.g. monitoring or registration for receipt of user log-on information, or the connection status of the users

Abstract

The invention discloses a network channel maintaining method based on a UDP protocol, which comprises the following steps: step 1, a terminal device establishes connection with a server and completes registration through the server; step 2, the terminal equipment and the server carry out network channel maintenance communication, and the method comprises the following steps: the terminal equipment sends a plurality of unidirectional heartbeat data packets to the server; the terminal equipment sends 1 bidirectional heartbeat data packet to the server, and the common time for sending the unidirectional heartbeat data packet and the bidirectional heartbeat data packet is heartbeat interval time; after receiving the bidirectional heartbeat data packet of the terminal equipment, the server sends a response data packet to the terminal equipment; and the terminal equipment receives the response data packet of the server, adjusts or maintains the heartbeat interval time, and increases the heartbeat interval time if the terminal equipment does not receive the response data packet for a plurality of times continuously. The invention prolongs the heartbeat interval time as far as possible on the premise of ensuring that the network channel is normally maintained so as to save the flow and adapt to different network provider core network environments.

Description

Network channel maintaining method based on UDP protocol
Technical Field
The present invention relates to a method for maintaining a mobile communication network channel, and more particularly, to a method for maintaining a network channel based on a UDP protocol.
Background
The mobile communication terminal physical network equipment (such as some remote controllers and remote detection equipment) can be connected with the server through a 2G, 3G and 4G network provided by a network operator through a TCP (transmission control protocol) protocol or a UDP (user datagram protocol) protocol to generate data interaction with the server. The tcp (transmission Control protocol) protocol, i.e. the transmission Control protocol, is a connection-oriented, reliable transport layer communication protocol based on byte streams, and is defined by RFC 793 of IETF; udp (user Datagram protocol), i.e., a user Datagram protocol, is a protocol that provides an application program with the capability of sending encapsulated IP packets without establishing a connection.
The server has fixed and open public network IP and port number, and the client can be connected at any time. The IP and the port number of the terminal equipment are allocated by the network provider and are dynamically allocated after the terminal equipment is arranged at various core network equipment of the network provider, so that the IP and the port number of a client are unknown to a server, the server and the terminal equipment want data interaction and must be connected by the client, the server sends data after the public network IP and the port number are allocated by the network provider, the public network IP and the port of the terminal equipment are visible to the server, and the server can actively send messages to the terminal equipment.
However, if the terminal device does not continuously transmit data, the IP and port allocated by the network provider will be disabled, and the server will not be able to actively transmit messages to the terminal device.
In order to enable the server and the terminal device to communicate, the current common solutions are:
1. the terminal regularly and actively acquires the message:
the scheme is suitable for equipment which only needs the terminal to send data to the server, and can ensure that the message which is hardly established is valid data, so that the flow consumption is very small, but the server cannot send the message to the terminal equipment because the public network address of the terminal is invisible.
2. A heartbeat mechanism is adopted to maintain a network channel:
the scheme adopts timing and server interactive data, for example, timing 30S sends a bidirectional heartbeat data packet to the server, and the server simultaneously gives a response to maintain a network channel, so that the server can know the network channel corresponding to the terminal equipment ID and can send a message to the terminal equipment at any time, but the bidirectional heartbeat data packet belongs to invalid data, so that the consumption of flow can be greatly increased; for example, if a bidirectional heartbeat packet is transmitted to the server at the timing 30S, the monthly traffic consumption is approximately 15M, and the consumed traffic is large. The bidirectional heartbeat data packet is a network detection packet which comprises a registration number, namely an ID, of the terminal device and needs a response of the server, and is used for detecting whether a network channel of the terminal device is changed and whether the server is online.
Disclosure of Invention
In order to solve the above problems, an object of the present invention is to provide a network channel maintaining method based on UDP protocol, which can maintain a network channel and save traffic.
The invention realizes the purpose through the following technical scheme:
a network channel maintaining method based on UDP protocol is used for communication between terminal equipment and a server, and comprises the following steps:
step 1, a terminal device establishes connection with a server and completes registration through the server; the method comprises the following steps:
step 1.1, the terminal equipment starts GPRS service and starts UDP protocol service;
step 1.2, the terminal equipment sends a registration packet to a server through a UDP protocol; the server is a known IP and port open server; the registration packet comprises a unique ID number of the terminal equipment and default heartbeat interval time;
step 1.3, the server registers the equipment after receiving the registration packet of the terminal equipment, sends a registration response packet to the terminal equipment, records the external network IP and the port number of the terminal equipment, which are distributed by a network provider, and finishes registration; the registration response packet comprises a unique ID number sent by the terminal equipment and a unique ID number which is distributed by the server and aims at the server;
step 2, the terminal equipment and the server carry out network channel maintenance communication, and the method comprises the following steps:
step 2.1, the terminal device sets heartbeat interval time as T seconds and sending times as N times, the terminal device sends (N-1) one-way heartbeat data packets to the server within (T-T/N) seconds, and the one-way heartbeat data packets refer to single-byte heartbeat data packets which do not need to be responded by the server;
step 2.2, after the terminal device sends (N-1) unidirectional heartbeat data packets, sending 1 bidirectional heartbeat data packet to the server within (T/N) seconds, wherein the bidirectional heartbeat data packet is a network detection packet which comprises a registration number (ID) of the terminal device and needs to be responded by the server and is used for detecting whether a network channel of the terminal device is changed and whether the server is on line; according to the steps 2.1 and 2.2, the total number of the data packets sent by the terminal device is N within a period time, including (N-1) unidirectional heartbeat data packets and 1 bidirectional heartbeat data packet, and the period time, i.e., the heartbeat interval time, is T seconds, including (T-T/N) seconds for sending the (N-1) unidirectional heartbeat data packets and (T/N) seconds for sending the 1 bidirectional heartbeat data packet;
step 2.3, after receiving the bidirectional heartbeat data packet of the terminal equipment, the server sends a response data packet to the terminal equipment to inform the terminal equipment of being online, and simultaneously detects whether a network channel corresponding to the registration number of the terminal equipment is changed; the specific method comprises the following steps: if the network channel changes and the data of the received N unidirectional heartbeat data packets are the same, the response data packet comprises information data for requiring the terminal equipment to adjust the T value, and the adjusting method adopts a conventional method according to actual needs, namely increasing the T value or reducing the T value; if the network channel is not changed, the response data packet is a data packet which indicates that the network is normal; if the registration number of the terminal equipment is not in the registration table of the server, the response data packet comprises information data for requiring the terminal equipment to be registered again;
step 2.4, the terminal equipment receives a response data packet of the server, if the response data packet comprises information data for requiring the terminal equipment to adjust the T value, the T value is adjusted according to the requirement, namely the T value is increased or reduced; if the response data packet is a data packet which indicates that the network is normal, the unidirectional heartbeat data packet and the bidirectional heartbeat data packet are continuously sent to the server according to the existing T value; if the response data packet comprises information data requiring the terminal equipment to be registered again, the terminal equipment is registered again according to the requirement; and if the terminal equipment does not receive the response data packet of the server, continuously sending the bidirectional heartbeat data packet to the server after T seconds, and if the terminal equipment does not receive the response data packet of the server for multiple times continuously, increasing the value T and then continuously sending the bidirectional heartbeat data packet to the server until the response data packet of the server is received.
According to the test, T in the step 2.1 is preferably 110, and N is preferably 6.
Specifically, in step 1.2, the unique ID number of the terminal device is generally a SIM card number.
The invention has the beneficial effects that:
the invention establishes connection through server registration, maintains network connection by periodically sending a plurality of unidirectional heartbeat data packets and a bidirectional heartbeat data packet, dynamically adjusts heartbeat interval time by the server, prolongs the heartbeat interval time as far as possible on the premise of ensuring normal maintenance of a network channel so as to save flow, and adapts to different network provider core network environments; taking 64 bytes of a unidirectional heartbeat data packet, 128 bytes of a bidirectional heartbeat data packet, 110 bytes of T and 6 of N as examples, the data packets required for one day are 24 (hours) × 60 (minutes) × 60 (seconds)/110 =785, including 655 unidirectional heartbeat data packets and 130 bidirectional heartbeat data packets, the traffic required for one day is 655 × 64+130 × 128=41920+16640=58560 bytes, the traffic required for one month is 58560 × 30=1756800 bytes, which is about 1.7M, the traffic required for one month is about 2.2M when some modules and core network data interaction traffic are added, and the traffic required for the next month in the traditional heartbeat mechanism is about 15M, so that the invention has obvious traffic saving effect; the invention is particularly suitable for GPRS Internet of things terminal equipment which is sensitive to network data flow consumption, keeps a network channel smooth and can send messages to the terminal equipment by a server at any time.
Drawings
Fig. 1 is a flowchart of a network channel maintenance method based on UDP protocol according to the present invention.
Detailed Description
The invention will be further described with reference to the accompanying drawings in which:
as shown in fig. 1, the network channel maintaining method based on UDP protocol according to the present invention is used for communication between a terminal device and a server, and includes the following steps:
step 1, a terminal device establishes connection with a server and completes registration through the server; the method comprises the following steps:
step 1.1, terminal equipment (usually a smart phone) starts GPRS service and starts UDP protocol service;
step 1.2, the terminal equipment sends a registration packet to a server through a UDP protocol; the server is a known IP and port open server; the registration packet comprises a unique ID number of the terminal equipment and default heartbeat interval time; the unique ID number of the terminal equipment is an SIM card number;
step 1.3, the server registers the equipment after receiving the registration packet of the terminal equipment, sends a registration response packet to the terminal equipment, records the external network IP and the port number of the terminal equipment, which are distributed by a network provider, and finishes registration; the registration response packet comprises a unique ID number sent by the terminal equipment and a unique ID number which is distributed by the server and aims at the server;
step 2, the terminal equipment and the server carry out network channel maintenance communication, and the method comprises the following steps:
step 2.1, the terminal device sets heartbeat interval time as T seconds and sending times as N times, the terminal device sends (N-1) one-way heartbeat data packets to the server within (T-T/N) seconds, and the one-way heartbeat data packets refer to single-byte heartbeat data packets which do not need to be responded by the server; wherein, T is preferably 110, and N is preferably 6;
step 2.2, after the terminal device sends (N-1) unidirectional heartbeat data packets, sending 1 bidirectional heartbeat data packet to the server within (T/N) seconds, wherein the bidirectional heartbeat data packet is a network detection packet which comprises a registration number (ID) of the terminal device and needs to be responded by the server and is used for detecting whether a network channel of the terminal device is changed and whether the server is on line; according to the steps 2.1 and 2.2, the total number of the data packets sent by the terminal device is N within a period time, including (N-1) unidirectional heartbeat data packets and 1 bidirectional heartbeat data packet, and the period time, i.e., the heartbeat interval time, is T seconds, including (T-T/N) seconds for sending the (N-1) unidirectional heartbeat data packets and (T/N) seconds for sending the 1 bidirectional heartbeat data packet;
step 2.3, after receiving the bidirectional heartbeat data packet of the terminal equipment, the server sends a response data packet to the terminal equipment to inform the terminal equipment of being online, and simultaneously detects whether a network channel corresponding to the registration number of the terminal equipment is changed; the specific method comprises the following steps: if the network channel changes and the data of the received N unidirectional heartbeat data packets are the same, the response data packet comprises information data for requiring the terminal equipment to adjust the T value, and the adjusting method adopts a conventional method according to actual needs, namely increasing the T value or reducing the T value; if the network channel is not changed, the response data packet is a data packet which indicates that the network is normal; if the registration number of the terminal equipment is not in the registration table of the server, the response data packet comprises information data for requiring the terminal equipment to be registered again;
step 2.4, the terminal equipment receives a response data packet of the server, if the response data packet comprises information data for requiring the terminal equipment to adjust the T value, the T value is adjusted according to the requirement, namely the T value is increased or reduced; if the response data packet is a data packet which indicates that the network is normal, the unidirectional heartbeat data packet and the bidirectional heartbeat data packet are continuously sent to the server according to the existing T value; if the response data packet comprises information data requiring the terminal equipment to be registered again, the terminal equipment is registered again according to the requirement; and if the terminal equipment does not receive the response data packet of the server, continuously sending the bidirectional heartbeat data packet to the server after T seconds, and if the terminal equipment does not receive the response data packet of the server for multiple times continuously, increasing the value T and then continuously sending the bidirectional heartbeat data packet to the server until the response data packet of the server is received.
Description of the drawings: the above contents correspond to the contents of fig. 1 but are not exactly the same, for example, the DTU in fig. 1 represents a terminal device of the above contents, the network maintenance packet in fig. 1 includes a unidirectional heartbeat packet and a bidirectional heartbeat packet of the above contents, and fig. 1 also includes partial codes of response contents, which are adaptive change processes for adapting to different requirements and do not affect the protection scheme of the present invention.
The above embodiments are only preferred embodiments of the present invention, and the technical solutions of the present invention should not be limited as long as they can be realized on the basis of the above embodiments without creative efforts, and all the technical solutions should be considered to fall within the protection scope of the patent of the present invention.

Claims (3)

1. A network channel maintaining method based on UDP protocol is used for communication between terminal equipment and a server, and is characterized in that: the method comprises the following steps:
step 1, establishing connection between the terminal equipment and the server and completing registration through the server, wherein the method comprises the following steps:
step 1.1, the terminal equipment starts GPRS service and starts UDP protocol service;
step 1.2, the terminal equipment sends a registration packet to a server through a UDP protocol; the server is a known IP and port open server; the registration packet comprises a unique ID number of the terminal equipment and default heartbeat interval time;
step 1.3, the server registers the equipment after receiving the registration packet of the terminal equipment, sends a registration response packet to the terminal equipment, records the external network IP and the port number of the terminal equipment, which are distributed by a network provider, and finishes registration; the registration response packet comprises a unique ID number sent by the terminal equipment and a unique ID number which is distributed by the server and aims at the server;
step 2, the terminal equipment and the server carry out network channel maintenance communication, and the method comprises the following steps:
step 2.1, the terminal device sets heartbeat interval time as T seconds and sending times as N times, the terminal device sends (N-1) one-way heartbeat data packets to the server within (T-T/N) seconds, and the one-way heartbeat data packets refer to single-byte heartbeat data packets which do not need to be responded by the server;
step 2.2, after the terminal device sends (N-1) unidirectional heartbeat data packets, sending 1 bidirectional heartbeat data packet to the server within (T/N) seconds, wherein the bidirectional heartbeat data packet is a network detection packet which comprises a registration number (ID) of the terminal device and needs to be responded by the server and is used for detecting whether a network channel of the terminal device is changed and whether the server is on line;
step 2.3, after receiving the bidirectional heartbeat data packet of the terminal equipment, the server sends a response data packet to the terminal equipment to inform the terminal equipment of being online, and simultaneously detects whether a network channel corresponding to the registration number of the terminal equipment is changed; the specific method comprises the following steps: if the network channel changes and the data of the received N unidirectional heartbeat data packets are the same, the response data packet comprises information data for requiring the terminal equipment to adjust the T value; if the network channel is not changed, the response data packet is a data packet which indicates that the network is normal; if the registration number of the terminal equipment is not in the registration table of the server, the response data packet comprises information data for requiring the terminal equipment to be registered again;
step 2.4, the terminal equipment receives a response data packet of the server, if the response data packet comprises information data for requiring the terminal equipment to adjust the T value, the T value is adjusted according to the requirement, namely the T value is increased or reduced; if the response data packet is a data packet which indicates that the network is normal, the unidirectional heartbeat data packet and the bidirectional heartbeat data packet are continuously sent to the server according to the existing T value; if the response data packet comprises information data requiring the terminal equipment to be registered again, the terminal equipment is registered again according to the requirement; and if the terminal equipment does not receive the response data packet of the server, continuously sending the bidirectional heartbeat data packet to the server after T seconds, and if the terminal equipment does not receive the response data packet of the server for multiple times continuously, increasing the value T and then continuously sending the bidirectional heartbeat data packet to the server until the response data packet of the server is received.
2. The UDP protocol based network channel maintenance method of claim 1, wherein: t in the step 2.1 is 110, and N is 6.
3. The UDP protocol based network channel maintenance method according to claim 1 or 2, wherein: in the step 1.2, the unique ID number of the terminal device is the SIM card number.
CN201910790340.1A 2019-08-26 2019-08-26 Network channel maintaining method based on UDP protocol Active CN110365803B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910790340.1A CN110365803B (en) 2019-08-26 2019-08-26 Network channel maintaining method based on UDP protocol

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910790340.1A CN110365803B (en) 2019-08-26 2019-08-26 Network channel maintaining method based on UDP protocol

Publications (2)

Publication Number Publication Date
CN110365803A CN110365803A (en) 2019-10-22
CN110365803B true CN110365803B (en) 2021-11-02

Family

ID=68225410

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910790340.1A Active CN110365803B (en) 2019-08-26 2019-08-26 Network channel maintaining method based on UDP protocol

Country Status (1)

Country Link
CN (1) CN110365803B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110974204A (en) * 2019-12-25 2020-04-10 杭州涂鸦信息技术有限公司 Method, system and device for realizing bidirectional heartbeat mechanism
CN112437144B (en) * 2020-11-16 2021-10-08 成都渊数科技有限责任公司 Method and system for increasing access number of single edge server iot equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104301423A (en) * 2014-10-24 2015-01-21 北京奇虎科技有限公司 Heartbeat message sending method, device and system
WO2015196790A1 (en) * 2014-06-26 2015-12-30 Tencent Technology (Shenzhen) Company Limited Method and system for heartbeat adaptation
CN105933199A (en) * 2016-04-08 2016-09-07 武汉斗鱼网络科技有限公司 Method for maintaining heartbeat connection, gateway and chat server
CN106713012A (en) * 2016-11-25 2017-05-24 深圳怡化电脑股份有限公司 Communication anomaly detection method and apparatus

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8756708B2 (en) * 2012-07-13 2014-06-17 NETFLIX Inc. System and method for detecting active streams using a heartbeat and secure stop mechanism

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2015196790A1 (en) * 2014-06-26 2015-12-30 Tencent Technology (Shenzhen) Company Limited Method and system for heartbeat adaptation
CN104301423A (en) * 2014-10-24 2015-01-21 北京奇虎科技有限公司 Heartbeat message sending method, device and system
CN105933199A (en) * 2016-04-08 2016-09-07 武汉斗鱼网络科技有限公司 Method for maintaining heartbeat connection, gateway and chat server
CN106713012A (en) * 2016-11-25 2017-05-24 深圳怡化电脑股份有限公司 Communication anomaly detection method and apparatus

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
GPRS数据分包长度和心跳包间隔性能分析;田锦;《电讯技术》;20120430;全文 *

Also Published As

Publication number Publication date
CN110365803A (en) 2019-10-22

Similar Documents

Publication Publication Date Title
US8023477B2 (en) Managing connections in a wireless communications network
CN102223257B (en) Heartbeat interval adjusting method, server, client terminal and communication system
WO2013094895A1 (en) Method and apparatus for processing messages
US20070057663A1 (en) Reduced Power Consumption in a Communication Device
CN110365803B (en) Network channel maintaining method based on UDP protocol
CN105991712B (en) A kind of network acceleration device
CN102684949B (en) Method and device for processing heartbeat data packet under persistent connection, and client
CN100550763C (en) The management method of the network equipment and network management system
US8310969B2 (en) Mobile device and power saving method thereof
JP5678198B2 (en) Mobile Internet service realization method, gateway, proxy and system
US20090196281A1 (en) ENERGY STAR compliant Voice over Internet Protocol (VoIP) telecommunications network including ENERGY STAR compliant VoIP devices
CN103795632A (en) Data message transmission method, related equipment and system
CN110703617A (en) Intelligent home control system based on MQTT
EP2795957A1 (en) Bandwidth management in a home network
CN105262836A (en) Information push method of server and push information reception method of client
GB2466196B8 (en) Communications system and method
CN101990283A (en) Wireless communication device and electricity saving method thereof
CN111417182A (en) Data transmission method, device, storage medium, processor and system
CN106231533A (en) The method and apparatus of short haul connection
CN103379130A (en) Network access system and method based on application layer data
CN103259713B (en) Message exchange system and method
CN101951642A (en) Method and device for regulating download speed of mobile terminal
CN101064671A (en) Method for processing P2P technique based network video signal
CN109922159B (en) Cloud bidirectional virtual connection method between Internet of things devices
CN103686849B (en) The sending method and terminal of periodic data message

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