Networking Forums

Networking Forums > Computer Networking > Linux Networking > how get state of socket in c

Reply
Thread Tools Display Modes

how get state of socket in c

 
 
tomek
Guest
Posts: n/a

 
      11-30-2004, 03:15 PM
Hello

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?

Regards
Tomek

--
Don't panic - we're from poland

 
Reply With Quote
 
 
 
 
Rick Jones
Guest
Posts: n/a

 
      12-01-2004, 06:17 PM
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...
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test socket on Master Socket not working Kevin Cowans Broadband 14 11-15-2006 09:17 PM
How to determine is socket in working state Alexander Krizhanovsky Linux Networking 0 06-27-2006 02:39 PM
10038 Socket Operation on non-socket error Tim G Windows Networking 1 09-26-2004 03:04 PM
WLAN Monitor 10038 Socket operation on non-socket Bill Windows Networking 1 03-01-2004 10:34 PM
So many socket connections in FIN_WAIT_1 state Ankur Desai Windows Networking 0 01-24-2004 07:06 AM



1 2 3 4 5 6 7 8 9 10 11