-
Hi
I have developed a winsock application.
Everything is working fine except for client disconnections.
If a client program is closed, the Winsock Close event occurs on the server program.
However, if windows crashes, or the client computer is just turned off, the close event does not occur. How can I get it to occur?
Also, what is a good way of checking if a connection exists, even if the close event hasn't happened?
My program uses a control array so that multiple clients can connect at the same time.
Thanks.
-
-
Thanks for replying...
...but what if network traffic causes the ping response to be delayed, and then my program boots them off.
Is there no other way to do it?
-
Server sends a string .
Client recieves string and sends back to server .
The server recieves a response and know client is still logged in .
Server waits 30 secs and does it again .
Thats the only thing I Can Think of .
or use winsock(index).state to see what state it's in
-
Try the code below to determine the connection state, but i didnt check it on the internet, just used it over LAN and it worked fine.
Code:
Private Sub Timer1_Timer()
If Winsock1.State = sckConnected Then
Label1.Caption = "Connected"
Else
Label1.Caption = "Disconnected"
End
End Sub
I dont think the close event will trigger if the computer is switched off directly, or if windows crashes, however if the user shutsdown windows properly, you might be able to use the following code.
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Winsock1.Close
End Sub