CN109922059A - The method that client and server-side based on socket keep connection - Google Patents

The method that client and server-side based on socket keep connection Download PDF

Info

Publication number
CN109922059A
CN109922059A CN201910147934.0A CN201910147934A CN109922059A CN 109922059 A CN109922059 A CN 109922059A CN 201910147934 A CN201910147934 A CN 201910147934A CN 109922059 A CN109922059 A CN 109922059A
Authority
CN
China
Prior art keywords
client
server
thread
data
detection
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
Application number
CN201910147934.0A
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.)
Nanjing Kegu Intelligent Technology Co Ltd
Original Assignee
Nanjing Kegu Intelligent Technology 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 Nanjing Kegu Intelligent Technology Co Ltd filed Critical Nanjing Kegu Intelligent Technology Co Ltd
Priority to CN201910147934.0A priority Critical patent/CN109922059A/en
Publication of CN109922059A publication Critical patent/CN109922059A/en
Pending legal-status Critical Current

Links

Landscapes

  • Computer And Data Communications (AREA)

Abstract

The invention discloses the communication means of a kind of client based on socket and server-side, steps are as follows: the listening thread for starting server-side monitors specified port numbers, while starting detection thread;Client creates socket, is connected to specified services end;After both sides establish connection, client numbers the unique client of oneself, is sent to server-side;After server-side receives client number, by client number, client ip address, client end slogan and the time preservation for receiving client data;According to the circulation time of setting, thread is detected to client address and sends detection information;After client receives detection information, client is returned immediately and is numbered to server-side;Server-side numbers the data for updating and saving in server-side according to the client of return.The present invention is because there is client number, and orientable which client determine connection be.Can know that specifically which client there is a problem when a problem occurs, be accurately positioned, solves rapid.

Description

The method that client and server-side based on socket keep connection
Technical field
The present invention relates to field of communication technology, specifically a kind of client and server-side based on communication keeps the side of connection Method.
Background technique
Socket (socket) is the intervening software abstraction layer of application layer and TCP/IP protocol suite communication, is that its one group connects Mouthful.Comprising carrying out the necessary information of network communication.
Multiple TCP connections or multiple program process may be needed through the same Transmission Control Protocol port transmission data, In order to distinguish different program process and connection, operating system provides for application program and TPC/IP protocol interaction socket.Application layer and transport layer can be distinguished logical from different application process or network connection by socket Letter realizes the concurrent services of data transmission.
The system communicated on internet using TCP, can all face frequent disconnection, network topology is numerous and complicated It is complicated and multiple switch, router, firewall etc. hardware device may be passed through between client to server-side, often The related setting of a hardware device also disunity, along with congestion, the delay etc. being likely to occur in network, so that we are being handled It is very intractable when going offline.
In order to solve delay and congestion problems, currently existing scheme is on Socket by the inspection built in ICP/IP protocol layer Whether survey method survives to judge to connect, for example, setting detection in 2 seconds is primary, the throw exception when detection more than 10 seconds fails.Root According to actual test, this setting can solve a part of problem, but still suffer from some connections upon opening, considerably beyond 10 Second, which is just perceived, to go offline.Moreover, that server-side can not determine connection is that visitor if the address client ip changes Family end.
Summary of the invention
The technical problem to be solved by the present invention is in view of the deficiency of the prior art, and provide it is a kind of can be accurate Positioning and the client and server-side communication means based on socket that can promptly and accurately detect.
In order to solve the above technical problems, the technical solution adopted by the present invention is that:
A kind of communication means of client and server-side based on socket, which is characterized in that step are as follows:
S1 starts the listening thread of server-side, monitors specified port numbers, while starting detection thread;
S2 client creates socket, is connected to specified services end;
After S3 both sides establish connection, client numbers the unique client of oneself, is sent to server-side;
After S4 server-side receives client number, following data is saved, data include that the client of client is compiled Number, client ip address, client end slogan and the time for receiving client data;
S5 is according to the circulation time of setting, and the data that detection thread taking-up saves, send to client address and client is arranged Good detection information;
After S6 client receives detection information, client is returned immediately and is numbered to server-side;
S7 server-side receives the client number of return, and the data for updating and saving in server-side are numbered according to the client of return.
The circulation time that detection thread is set, detection thread was sent according to the circulation time of setting to client as 5-60 seconds One-time detection information.
The detection information is { action:1;Model:1 }).
The time of detection thread loops can freely set according to the actual situation, such as set 5 seconds circulation primaries, then detect thread Every five seconds sends a data to client.
If some client there is a problem, the corresponding data of the client (time) cannot be more in database Newly, it is easy to judge whether go offline.At this moment technical staff, which can be contacted, goes to given client end to check problem.
Compared with prior art, the beneficial effect of technical solution of the present invention is:
1. because there is client number, orientable which client determine connection be.It can know that when a problem occurs Specifically which client there is a problem, be accurately positioned, and solve rapid.
2. detection time in time, accurately, is not in the phenomenon that being not detected after connection disconnects.
3. being not necessarily limited the ip and port numbers of client, more flexibly.
4. the time of cycle detection freely configures, it is applicable in various occasions.
Detailed description of the invention
Fig. 1 is the flow diagram of communication means of the present invention.
Specific embodiment
With reference to the accompanying drawing, it elaborates to the present invention:
The present invention is based on the communication means of the client of socket and server-side, detailed process is as follows:
S5 starts the listening thread of server-side, monitors specified port numbers (such as 8543), while starting detection thread;
S2 client creates socket, is connected to specified services end, such as (127.0.0.1:8543)
After S3 both sides establish connection, client oneself number (unique encodings that client and server-side have been appointed, such as ({ code:10001 }), is sent to server-side.
After S4 server-side receives data, the number of client, IP address, port numbers receive the time guarantor of data It stores away (such as: { code:10001;ip:192.168.30.86:1230;Time:2019-01-18 09:00:00 }).
S5 detects thread and takes out the data saved, sends detection information (as sent { action:1 to client address; Model:1 }).
S6 client (such as has received { action:1 after receiving detection information;Model:1 }), it returns message to immediately Server-side (such as { code:10001 }).
S7 server-side, which receives, returns to message ({ code:10001 }), according to returning to message, the information in more new database, such as
({ code:10001;ip:192.168.30.86:1230;Time:2019-01-18 09:00:05 }).
The time of detection thread loops can freely set according to the actual situation (as set 5 seconds circulation primaries, then detects thread Every five seconds sends a data, general setting 5-60 seconds or so to client), the step of S5-S7 is repeated according to the time of setting later Suddenly.
If a certain client do not replied for a long time (it is time that such as 10001 client last time, which receive the time of information: 2019-01-18 09:00:00, now 2019-01-18 09:00:30), then it is assumed that connection there is a problem, the client End has gone offline, and will send a warning message to technical staff (such as: short message push).At this moment technical staff can go to given client end Check problem.

Claims (4)

1. a kind of communication means of client and server-side based on socket, which is characterized in that step are as follows:
S1 starts the listening thread of server-side, monitors specified port numbers, while starting detection thread;
S2 client creates socket, is connected to specified services end;
After S3 both sides establish connection, client numbers the unique client of oneself, is sent to server-side;
After S4 server-side receives client number, following data is saved, data include that the client of client is compiled Number, client ip address, client end slogan and the time for receiving client data;
S5 is according to the circulation time of setting, and the data that detection thread taking-up saves, send to client address and client is arranged Good detection information;
After S6 client receives detection information, client is returned immediately and is numbered to server-side;
S7 server-side receives the client number of return, and the data for updating and saving in server-side are numbered according to the client of return.
2. communication means according to claim 1, which is characterized in that it is characterized by: when the circulation of detection thread setting Between be 5-60 second, detection thread is according to circulation time of setting to client transmission one-time detection information.
3. communication means according to claim 2, which is characterized in that it is characterized by: when the circulation of detection thread setting Between be 5 seconds, detection thread every five seconds to client send one-time detection information.
4. communication means according to claim 1 to 3, which is characterized in that it is characterized by: the detection information is {action:1;Model:1 }).
CN201910147934.0A 2019-02-28 2019-02-28 The method that client and server-side based on socket keep connection Pending CN109922059A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910147934.0A CN109922059A (en) 2019-02-28 2019-02-28 The method that client and server-side based on socket keep connection

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910147934.0A CN109922059A (en) 2019-02-28 2019-02-28 The method that client and server-side based on socket keep connection

Publications (1)

Publication Number Publication Date
CN109922059A true CN109922059A (en) 2019-06-21

Family

ID=66962628

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910147934.0A Pending CN109922059A (en) 2019-02-28 2019-02-28 The method that client and server-side based on socket keep connection

Country Status (1)

Country Link
CN (1) CN109922059A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112583672A (en) * 2020-12-18 2021-03-30 北京睿芯高通量科技有限公司 TCP server stability testing method based on timestamp
CN114979233A (en) * 2022-07-19 2022-08-30 深圳市亿联无限科技有限公司 Method and system for realizing synchronous and asynchronous call between modules based on domain socket

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101035037A (en) * 2007-04-17 2007-09-12 华为技术有限公司 Method, system and related device for detecting the network communication quality
CN102761518A (en) * 2011-04-25 2012-10-31 中兴通讯股份有限公司 Communication method and server supporting multiple socket connection modes
US10225170B2 (en) * 2012-07-13 2019-03-05 Netflix, Inc. System and method for detecting active streams using a heartbeat and secure stop mechanism

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101035037A (en) * 2007-04-17 2007-09-12 华为技术有限公司 Method, system and related device for detecting the network communication quality
CN102761518A (en) * 2011-04-25 2012-10-31 中兴通讯股份有限公司 Communication method and server supporting multiple socket connection modes
US10225170B2 (en) * 2012-07-13 2019-03-05 Netflix, Inc. System and method for detecting active streams using a heartbeat and secure stop mechanism

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112583672A (en) * 2020-12-18 2021-03-30 北京睿芯高通量科技有限公司 TCP server stability testing method based on timestamp
CN112583672B (en) * 2020-12-18 2023-05-19 北京睿芯高通量科技有限公司 TCP server stability test method based on time stamp
CN114979233A (en) * 2022-07-19 2022-08-30 深圳市亿联无限科技有限公司 Method and system for realizing synchronous and asynchronous call between modules based on domain socket

Similar Documents

Publication Publication Date Title
CN108134684B (en) BMCIP address management system, management terminal and management method
US20070180103A1 (en) Facilitating event management and analysis within a communications environment
US20100100768A1 (en) Network failure detecting system, measurement agent, surveillance server, and network failure detecting method
EP3222003B1 (en) Inline packet tracing in data center fabric networks
JP2006031685A (en) System for managing socket connection and method for checking socket connection state
CN104202334B (en) A kind of method and device for establishing network connection
CN107360239A (en) A kind of client connection status detection method and system
CN107133041B (en) Data notification method and device
EP3007386B1 (en) Apparatus and method for analyzing a control network
CN109922059A (en) The method that client and server-side based on socket keep connection
CN109075996A (en) For monitoring the monitoring controller and the therefore method that executes of network performance
US20150236920A1 (en) Method and apparatus for determining connection information of a link
WO2011123003A1 (en) An operations, administrations and management proxy and a method for handling operations, administrations and management messages
CN109634260A (en) Method and system are monitored online in vehicle control device
CN104243239A (en) State inspection method and device for controllers in SDN clusters
CN106375152A (en) Method for processing communication abnormality of Client/Server (C/S) architecture
US8611231B2 (en) Connectivity fault management for ethernet tree (E-Tree) type services
CN105871661B (en) Public network server detection method and detecting server
CN110908872A (en) Server state detection method and system
JP2007158569A (en) Network fault detecting apparatus
CN111565133B (en) Private line switching method and device, electronic equipment and computer readable storage medium
CN107566036A (en) Mistake in automatic detection communication and automatically determine the wrong source
US20080181215A1 (en) System for remotely distinguishing an operating system
CN104811343A (en) Network detection method and system of peer-to-peer network
CN103731315A (en) Server failure detecting method

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

Application publication date: 20190621

WD01 Invention patent application deemed withdrawn after publication