(VB6)
I'm having a timing issue with Winsock (perhaps it's an understanding issue too).
I have a TCP chat program, and I'm trying to account for a 'broken connection' with Winsock. For example, if a PeerA suddenly quits (crash, machine shut down, etc), then PeerB doesn't know the connection is lost.
Winsock.State does not accuratley reflect this - it still thinks sckOpen or sckConnected is true. Of course Winsock.Send does not throw an error if the connection is gone!
So the only way to verify the connection between PeerB and PeerA is to 'ping'
PeerA prior to trying to chat with it.
This is the problem:
I'd like to ping PeerA and see if there is a response prior to each attempt to Send.
When I have a Sub that executes the Winsock "Send" method, the Winsock "DataArrival" event doesn't fire until the Sub is ended, and no other routine is running.
The problem is that I'd like the return data value while still in the original Sub.
For example (pseudo code):
Code:
Sub SendIt()
Winsock1.Send "Hello"
If returnVal=True then
...more code...
else
...even more code....
end if
End Sub
Sub Winsock_DataArrival(...)
...process data....
If data=x then
returnVal=True
else
returnVal=False
end if
End Sub
Is there a way to execute a "Send" and get the resulting "Arrival"
without sitting in some kind of horrible loop?