No error on lost vpn connection

Hello,

i connect to a tcp socket on a remote machine via my barracuda vpn client. Now, if i disconnect the vpn connection, there is no error given back to socket.lastError, Socket.IsConnected stays true…

So how can i catch it, if the connection is lost?

TCP doesn’t immediately do anything when you pull a cable out or lose a connection. It literally doesn’t notice until you try to use the broken connection and then you get an error which you then deal with.

thanks for that…

so now i placed a global timer which is trying to send a string every 3 seconds to that socket:

for i as Integer = 0 to client_count.Ubound
client_count(i).ClientSocket.write(“a”)
next

if the vpn connection is lost, then that should have thrown an error then, but it doesn’t…

what does socket.poll actually do?

Writing a single character may not cause the socket to actually try to send the data. A write followed by a flush should though. This is going to make your TCP connections very “chatty”.

did a write followed by a flush… nothing, no error.

the only thing which gives back an error is setting the global timer to

for i as Integer = 0 to client_count.Ubound
client_count(i).ClientSocket.connect
next

regardless if the socket is still connected. But there must be a “better” way of doing this…?

what i found out is that only if the remote machines socket is in your “own” network (eg. 10.0.0.2 and client socket 10.0.0.3) then its given back an error but if the remote socket is in another network (eg. 172.25.2.100) then its not given back an error, even if the remote socket connection can’t be established because vpn isn’t connected… i mean it MUST give back an error because the client socket is not reachable… or am i wrong?

i now solved it by sending a “alive” string every 10 seconds from the socket, check the string and empty it, if it don’t fills up again the connection is dead…