Socket tcp server that does not 'hear' client disconnection

amorosik

Member
Local time
Today, 07:08
Joined
Apr 18, 2020
Messages
540
I have an Access procedure, which I will call A which receives commands from another program which I will call B
Procedure A opens a tcp socket and listens on the indicated port
I use the classic MsWinsck.ocx, loaded between the references and then used in the code with the classic:

Set tcpServer = New MSWinsockLib.Winsock
tcpServer.Protocol = sckTCPProtocol
tcpServer.LocalPort = "12345"
tcpServer.Listen

Accompanied by the three events
Private Sub tcpServer_ConnectionRequest (ByVal requestID As Long)
Private Sub tcpServer_DataArrival (ByVal bytesTotal As Long)
Private Sub tcpServer_Close ()
that manage the arrival of a client, the arrival of data, the closure of the connection

Bon, everything works as expected, program A starts, then program B starts, from B I fire commands and A receives, as expected If B (the client) stays on and A turns off, on B's code there is a routine that tests the connection every x seconds and when I turn on A again, program B reconnects automatically, as requested

But, on the contrary, I can't intercept it, I mean if A (the server) stays on and B (the client) turns off, procedure A can't 'feel' that the connection is gone
I thought the tcpServer_Close () was triggered but it isn't

So the question is: how to understand from the vba code (the server) that the connection has been interrupted?
I thought about pinging from server to client periodically and it would already work, but I hope there is a more elegant system
What are you say?
 
I note your question has yet to receive a reply. Hence, I am bumping it up the list a bit so that it gets another Look...
 
Unfortunately, using the client-server method, your set-up is one-sided. Most TCP-based protocols have an "Acknowledge" feature that if you send to B, then B acknowledges to A on another negotiated channel.

If you put a timer on the message exchange, you could send to B and then have a timer running for A that looks for the ACK response. If you don't get one in X seconds (typically 30 but pick the time right for you), then you declare a network session drop.
 

Users who are viewing this thread

Back
Top Bottom