address@hidden wrote:
Hello,
I have a simple tcp-server program derived from TCPSession.
My problem now is how to detect disconnected sessions.
1. disconnect by client, solved by messages from Wolfgang and
Christian. Return 0 bytes read.
2. disconnect by unplugging the network cable. HyperTerminal (my
Client on Windows side) detects that the connection lost.
I already tried the bad() function and pendigError. But it seems
everything normal.
btw. What I expect is a excpetion or pendingError.
My server program works under linux.
Many tanks for help,
Adib.
_______________________________________________
Bug-commoncpp mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/bug-commoncpp
Hi,
I came across this problem too. As far as I know there is no way to tell if
a 'remote' client has just gone away i.e. been switched off, disconnected
without being closed. I dont think Windows can detect it either, however it
will detect if its own network cable is unplugged.
The best you can do on linux is enable keepalives and change some kernel
parameter which modifies the timeout for keepalives.
The default is every 2 hours and waits for 9 failures before deciding a
connection is dead
for debian I use the following two lines in /etc/sysctl.conf
net/ipv4/tcp_keepalive_time = 30
net/ipv4/tcp_keepalive_probes = 3
This sets the keepalives to every 30 seconds, and will close the connection
if 3 keepalives are missed
You must also enable keepalives on your socket.
for a full description of the available variables, see here:
http://ipsysctl-tutorial.frozentux.net/chunkyhtml/tcpvariables.html
If you are not happy to do this is only other solution is to implement a
user-level keepalive system.
Hope this helps
Nick