Keep-alive header clarification

Where is this info kept (“this connection is between computer A and server F“)? A TCP connection is recognized by source IP and port and destination IP and port. Your OS, all intermediate session-aware devices and the server’s OS will recognize the connection by this. HTTP works with request-response: client connects to server, performs a … Read more

How to use SO_KEEPALIVE option properly to detect that the client at the other end is down?

To modify the number of probes or the probe intervals, you write values to the /proc filesystem like echo 600 > /proc/sys/net/ipv4/tcp_keepalive_time echo 60 > /proc/sys/net/ipv4/tcp_keepalive_intvl echo 20 > /proc/sys/net/ipv4/tcp_keepalive_probes Note that these values are global for all keepalive enabled sockets on the system, You can also override these settings on a per socket basis … Read more

Simple comet example using php and jquery

You should use polling, or use a web server which is specially conceived for long requests and COMET, with a good JS backend: function listen() { $.get(“/mylongrequestfile”, {}, function(data) { $(“#mydiv”).html(data); listen(); // then launch again })); }; Remember that COMET is “wait for data, if there’s data return and exit”, so JS backend will … Read more

python requests module and connection reuse

Global functions like requests.get or requests.post create the requests.Session instance on each call. Connections made with these functions cannot be reused, because you cannot access automatically created session and use it’s connection pool for subsequent requests. It’s fine to use these functions if you have to do just a few requests. Otherwise you’ll want to … Read more

WebSockets ping/pong, why not TCP keepalive?

The problems with TCP keepalive are: It is off by default. It operates at two-hour intervals by default, instead of on-demand as the Ping/Pong protocol provides. It operates between proxies rather than end to end. As pointed out by @DavidSchwartz, it operates between TCP stacks, not between the applications so therefore it doesn’t tell us … Read more

How to change tcp keepalive timer using python script?

You can set the TCP keepalive timers on an already-open socket using setsockopt(). import socket def set_keepalive_linux(sock, after_idle_sec=1, interval_sec=3, max_fails=5): “””Set TCP keepalive on an open socket. It activates after 1 second (after_idle_sec) of idleness, then sends a keepalive ping once every 3 seconds (interval_sec), and closes the connection after 5 failed ping (max_fails), or … Read more