Home > Software engineering >  Which has connection with the heartbeat packets to the WINSOCK control for effective management of t
Which has connection with the heartbeat packets to the WINSOCK control for effective management of t

Time:09-26

Which has connection with the heartbeat packets to the WINSOCK control for effective management of the source code

CodePudding user response:

RMB 500, QQ: 511606848

CodePudding user response:

Heartbeat packets understand principle also won't?
Very simple, is timing cycle sends a code to the server, the server over a period of time received drops is

CodePudding user response:

The client
 
Private Sub Form_Load ()
TcpClient. RemoteHost="127.0.0.1"
TcpClient. RemotePort=12345
End Sub
Private Sub cmdConnect_Click ()
'call the Connect method, the initialization connection,
TcpClient. Connect
End Sub
Private Sub tcpClient_DataArrival (ByVal bytesTotal As Long)
Dim strData As String
TcpClient. GetData strData
If strData="https://bbs.csdn.net/topics/02" Then
'//do anything
End the If
End Sub
Private Sub Timer1_Timer () '///real work
On the Error Resume Next
If tcpClient. State=7 Then
TcpClient. SendData publishes the event "01" '//agreement no. 01 - the client sends to the server in baotou, notification server himself alive, time interval for 8 s
The Else
Label1. Caption="has been disconnected from the server"
End the If
End Sub



The service side
 
Private intMax As Long
Private Sub Form_Load ()
IntMax=0
SckServer (0). LocalPort=12345
SckServer (0). Listen
End Sub
Private Sub sckServer_Close (Index As an Integer)
Dim As a Integer
For a=1 To ListView1. ListItems. Count
If sckServer (Index). RemoteHostIP=Split (ListView1. ListItems (a). The Text, ":") (1) Then
Me. The Caption=Split (ListView1 ListItems (a). The Text, ":") (1) & amp; "Referrals! - CLOSE to judge out!"
ListView1. ListItems. Remove (a)
SckServer (Index). Close
The Exit For
End the If
Next a
End Sub
Private Sub sckServer_ConnectionRequest (Index As an Integer, ByVal requestID As Long)
If the Index=0 Then
IntMax=intMax + 1
The Load sckServer (intMax)
SckServer (intMax). LocalPort=0
SckServer (intMax). Accept requestID
With ListView1
. ListItems. Add, Index & amp; ":" & amp; SckServer (Index). RemoteHostIP
. ListItems. Item (intMax). SubItems (1)=Format (Now, "HH: mm: ss") '//connect the first time is added to the customer on the status bar
End With
End the If
End Sub
Private Sub sckServer_DataArrival (Index As an Integer, ByVal bytesTotal As Long)
Dim GetStr As String
SckServer (Index). GetData GetStr, vbString
The Select Case GetStr
Case "01"
Dim As Integer I
For I=1 To ListView1. ListItems. Count
If the Split (ListView1 ListItems (I). The Text, ":") (1)=sckServer (Index). RemoteHostIP Then
ListView1. ListItems (I). SubItems (1)=Format (Now, "HH: mm: ss")
'MsgBox Format (Now, "HH: mm: ss")
End the If
Next
SckServer (Index). SendData publishes the event "02" '////agreement no. 02 server after receiving the information back to the client, can not reply, didn't do the client side processing
End the Select
End Sub
Private Sub sckServer_Error (Index As an Integer, ByVal Number As an Integer, the Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Dim As a Integer
For a=1 To ListView1. ListItems. Count
If sckServer (Index). RemoteHostIP=Split (ListView1. ListItems (a). The Text, ":") (1) Then
Me. The Caption=Split (ListView1 ListItems (a). The Text, ":") (1) & amp; "Referrals! - the ERROR judgment of "
ListView1. ListItems. Remove (a)
SckServer (Index). Close
The Exit For
End the If
Next a
End Sub
Private Sub Timer1_Timer () '///regularly check the client sign in case, if didn't check in regularly disconnect the client, the time interval of 35 s
Dim As Integer I
Dim j As Integer
If ListView1. ListItems. Count & gt; 0 Then
For I=1 To ListView1. ListItems. Count
J=Split (ListView1 ListItems (I). The Text, ":") (0) '///isolated INDEX
If Abs (DateDiff (" s ", the Format (Now, "HH: mm: ss"), the ListView1. The ListItems (I). SubItems (1))) & gt; 11 Then
Me. The Caption=Split (ListView1 ListItems (I). The Text, ":") (1) & amp; "Referrals! - timeout judgment out of "
ListView1. ListItems. Remove (I)
SckServer (j) Close
End the If
Next
The Else
The Exit Sub
End the If
End Sub

Casually found online, see the code under the principle of no problem
This is just the server test client, you can also write client testing server.
Principle about
Will see, not debugging
  • Related