For fun, I was writing load balancing on python and trying to determine the best (right?) Way to check if the port is accessible and the remote host still exists.
I find that after connecting it becomes difficult to tell when the remote host goes down. I continued to live, but I can not get him to recognize a broken connection earlier than a minute (I understand that polling more often than a minute may be unnecessary, but let's say I wanted) even after setting various TCP_KEEPALIVE options to the lowest.
When I use non-blocking sockets, I noticed that recv () will return an error ("resource is temporarily unavailable") when it reads from a live socket, but returns "" when reading from a dead (send and recv of 0 bytes, which may be the reason ?). However, this seems like a strange way to test it, and it does not allow to determine if the connected ones died, but after sending some data.
Besides connecting / disconnecting for each check, is there something I can do? Can I manually send tcp keepalive or establish a lower level connection that allows me to test the connection without sending real data that the remote server could potentially handle?
source
share