reactphp / socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP.

Home Page:https://reactphp.org/socket/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function to check remote server reachable

rrajkomar opened this issue · comments

Say you have a client inside a docker container that connects over a vpn to a remote server via some proxies.

How do you check at any given time that the remote server is still reachable ?

Currently I'm having the following issue :

Connection is correctly set up and started
At some point the vpn connection goes down yet the socket seems to remains open and connections are not closed (and do not trigger errors when attempting to send data to the remote server)

How do I ensure the connection will be closed if the tunnel to the remote server goes down ?
Or How do I check that the remote is still reachable before sending data tthrough the tunnel ?

@rrajkomar Thanks for this excellent question and welcome to the world of unreliable network transports!

How do you check at any given time that the remote server is still reachable ?

The gist is: The only thing you can rely on is that the network is unreliable.

If a peer "successfully closes" the connection (socket closed or application quit), then it should usually send a FIN flag which this library exposes as a "close" event.

If a peer "dies" without sending a TCP FIN (hard power off, sudden network change for mobile devices etc.), then it will not be able to tell you the connection is "dead".

It is very common to work around this issue by implementing some higher-level application timeout logic, such as sending a heartbeat message every once in a while. How this is best achieved depends entirely on the application protocol you're using, so I hope this helps getting the basic idea across.

I hope this helps 👍