checking wsock connection when improperly shutdown
My form sends a winsock.close message when a pc is properly shut down.
but when a pc is improperly shut down (accidentally unplugged), my form will not have the chance to send a winsock.close message thus the server detects the improperly shutdown client as still online.
what should i do in the server for me to detect the connection if the client is improperly shutdown?
i tried using checking the sckServer.State but the state in the server is still sckConnected.
Please help guys! Thanks!
Re: checking wsock connection when improperly shutdown
the best way to do this is to send out a ping to all the clients, this will determine accuratley if users online list.
so just have your server send out a packet, it could even just send "PING" and the client must send it back when it receives it, its simple code for your data arrival sub
if you need more help with the coding post back :thumb:
Re: checking wsock connection when improperly shutdown
Quote:
Originally Posted by the182guy
the best way to do this is to send out a ping to all the clients, this will determine accuratley if users online list.
so just have your server send out a packet, it could even just send "PING" and the client must send it back when it receives it, its simple code for your data arrival sub
if you need more help with the coding post back :thumb:
Hello, I am having problems.
I am using this code
VB Code:
Private Sub tmrConnChecker_Timer()
Dim i%
For i = 1 To Me.sckMain.UBound Step 1
replyReceived = False
If Me.sckMain(i).State = sckConnected Then
Me.sckMain(i).SendData "PING"
DoEvents
DoEvents
If replyReceived = False Then
Me.sckMain(i).Close
ChangeStatus pmOffline, i
End If
End If
Next i
End Sub
Private Sub sckMain_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim data$ ' variable where received data will be saved
Me.sckMain(Index).GetData data ' put received data to variable "data"
If data = "OVERRIDE" Then
ChangeStatus pmOverride, Index
ElseIf data = "PING_REPLY" Then
replyReceived = True
End If
End Sub 'sckMain_DataArrival()
The timer will send a "PING" to all and the client receives it, it will send a "PING_REPLY".
The problem is before the client has the chance to send "PING_REPLY", the server closes them.
Thanks for the help.
Re: checking wsock connection when improperly shutdown
you could do it like this..
have a timer with an interval or 2000 or 3000 maybe, the timer will wait for the ping replies, and when the code in the timer runs, it will check a boolean array which will have the replies from the clients.
so have a boolean array in a module, then have a button on the form to check the status, the button code will have a for loop to go through the winsocks and send a "PING" to all it will the activate the timer, which will wait for the replies.
in the data arrival sub parse the data and check if its "PING_REPLY" if it is, change the the data in the array to TRUE because that client has responded, then when the timer activates, loop through the array and count how many TRUE there is, that will be the number of connections