0

I am developing a TCP echo server using python and the socket library.

I'd like to have a timeout configured for each incoming connection. So to drop and close them if there is inactivity for a SOCK_TIMEOUT value.

This is achieve with the specific setting: client_sock.settimeout(SOCK_TIMEOUT)

At the same time I would like to maintain active the connection that use keepalive method. So, if a keepalive probe packet is received by the server from a given client I'd like to avoid the use of timeout to close this particular client/connection.

Problem clarification >> I'd like to have the server dropping every connection after 3 minutes of inactivity. This is achieved with the settimeout(SOCK_TIMEOUT) function. The main problem is that the current configuration and implementation of the TCP socket is not considering the keep-alive probe as "activity" thus, the connection is closed even if the probes are acknowledged.

Q1 >> Does this make sense?

I'd say this should be feasible. However, the socket server is unable to handle, as I desired, the keepalive probe. Because, even if those are acknowledged by the server, ACK is returned to each probe, the connection is closed at timeout.

Q2 >> Should I change the timeout implementation?

rebatoma
  • 101
  • 2
  • Afaik, tcp keepalive is transparent to the application. Ie: the application can't know this happens (even if it can configure settings for it to happen). If it can't know about it, this is moot. Why would you need to care about this? This looks like an [XY problem](https://xyproblem.info/): you need to solve a problem, but you never told us about it. – A.B May 21 '22 at 08:36
  • let me clarify the problem. I'd like to have the server dropping every connection after 3 minutes of inactivity. This is achieved with the `settimeout(SOCK_TIMEOUT)` function. The main problem is that the current configuration and implementation of the TCP socket is not considering the keep-alive probe as "activity" thus, the connection is closed even if the probes are acknowledged. – rebatoma May 22 '22 at 09:56

0 Answers0