How to test if a connection is still valid #542
-
I have a ReactPHP Server set up as a socket service in Laravel which listens for incoming connections and then receives data from a device. Unfortunately, this embedded device is not capable of a graceful shutdown so it does not close the connection when it is turned off. So when I look the ports on the firewall, it still shows them as open, thus not releasing those resources. I monitor both the 'end' and 'close' events on the server side, but neither of these events seems to be triggered when the device stops transmitting. So I just wanted to check, am I supposed to get an event if the connection is closed abruptly by the client or will I need to implement some sort of timeout? TIA |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @Sell24, thanks for bringing this up 👍 In a gist: If the device you're referring to is not capable of a graceful shutdown, it will also not send an There are similar tickets also covering this aspect like reactphp/socket#193, reactphp/socket#249 and others. Hope this helps :) |
Beta Was this translation helpful? Give feedback.
Hey @Sell24, thanks for bringing this up 👍
In a gist: If the device you're referring to is not capable of a graceful shutdown, it will also not send an
end
orclose
event. This means that if the device "dies" for any reason, it will be unable to notify you that the connection is "dead". To determine if your communication partner is still alive, you can implement higher-level application timeout logic, such as sending a heartbeat message every once in a while. If the device is dead and does not respond to your heartbeat message, you can close the connection.There are similar tickets also covering this aspect like reactphp/socket#193, reactphp/socket#249 and others.
Hope this helps :)