tomek <(E-Mail Removed)> wrote:
> I got client-server application, client working in linux - server in
> windows, but it doesn't matter. I want keeping connection for long
> time and make reconnections in linux client, for example: when
> physical connection between two machines is broken, client should be
> still alive, and reconnect to server when this will be possible. I
> don't know, how can I check current state of socket
> (connected/dissconnected) in linux. my application is wrote in pure
> c, but it isn't problem to migrate to c++ if this will be
> necessary. Now when I stop server I gets message: "Broken pipe" and
> client crashes. I know - this is when i write two times to non
> connected socked, but how can I check that socked is still connected
> without read from server? (server should not reply, but if this is
> only way, it will)
> Somebody help me?
You need to deal with the broken pipe error return and use that as
your "hey, the connection is down" notification.
Unless you enable TCP keepalives, if a connection is idle, there is no
traffic across it. If the remote goes away - particularly with an
otherwise evil, don't do that, abortive close (SO_LINGER stuff) or if
there are nasty end-to-end breaking firewalls along the way - it might
go away "silently" which means the local TCP will not detect it until
there is an attempt to send data - either your data, or a keepalive
probe.
If you need/want keepalive probes, you should _seriously_ consider
implementing them in your application itself. In that way you will
not depend on the TCP settings - at least not nearly so much, and
application-level keepalives are probably more portable - some stacks
allow tuning TCP keepalives per-connection, some dont, that sort of
thing.
rick jones
--
The computing industry isn't as much a game of "Follow The Leader" as
it is one of "Ring Around the Rosy" or perhaps "Duck Duck Goose."
- Rick Jones
these opinions are mine, all mine; HP might not want them anyway...

feel free to post, OR email to raj in cup.hp.com but NOT BOTH...