Networking Forums  

Go Back   Networking Forums > Networking Newsgroups > Linux Networking

Problem with sockets

Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2005, 10:39 PM
Default Problem with sockets



Hello,

I'd like to know if there is a way to know if one of the sides of a TCP
connection is down without sending any message, using some API (in UNIX)

Thanks

Andrea


Andrea Sini
Reply With Quote
  #2  
Old 02-03-2005, 08:32 PM
Pat_Tongco@spamcdo.org
Guest
 
Posts: n/a
Default Re: Problem with sockets

On 2005-02-02, Andrea Sini <(E-Mail Removed)> wrote:
> Hello,
>
> I'd like to know if there is a way to know if one of the sides of a TCP
> connection is down without sending any message, using some API (in UNIX)
>
> Thanks
>
> Andrea


Simply evaluating the value returned by
both sides' connect() call?


--
- Pat Tongco
2.6.10-ck5.012105
Reply With Quote
  #3  
Old 02-04-2005, 02:36 AM
jimxu
Guest
 
Posts: n/a
Default Re: Problem with sockets


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 2005-02-02, Andrea Sini <(E-Mail Removed)> wrote:
> > Hello,
> >
> > I'd like to know if there is a way to know if one of the sides of a TCP
> > connection is down without sending any message, using some API (in UNIX)
> >
> > Thanks
> >
> > Andrea

>
> Simply evaluating the value returned by
> both sides' connect() call?
>
>
> --
> - Pat Tongco
> 2.6.10-ck5.012105


If the connection is closed normally by the remote PC, you can receive a
message with NULL data.
If the connection is down for some link layer reason, (the network is down,
etc.), the OS can not detect it, I think
you can send keepalive message to detect it.
The connect() function can be used to setup a TCP/UDP connection, if you
want use this funtion to test a connected socket,
it is not so good. BTW, you can only get the return value asynchronous.

--
jimxu
*NO PAINS, NO GAINS*


Reply With Quote
  #4  
Old 02-04-2005, 06:36 PM
Phil Frisbie, Jr.
Guest
 
Posts: n/a
Default Re: Problem with sockets

Andrea Sini wrote:

> Hello,
>
> I'd like to know if there is a way to know if one of the sides of a TCP
> connection is down without sending any message, using some API (in UNIX)


No, but if one end closed gracefully then the other end will get a '0' return
from recv() to signal end of stream.

> Thanks
>
> Andrea


--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

Reply With Quote
  #5  
Old 02-04-2005, 06:58 PM
David Schwartz
Guest
 
Posts: n/a
Default Re: Problem with sockets


"Andrea Sini" <(E-Mail Removed)> wrote in message
news:_EcMd.488285$(E-Mail Removed)...

> I'd like to know if there is a way to know if one of the sides of a TCP
> connection is down without sending any message, using some API (in UNIX)


A moment's reflection should tell you that this is impossible in
principle. If the host disappears, how could you tell except by sending it a
message and noticing either its failure to respond or a resulting error?

DS


Reply With Quote
  #6  
Old 02-04-2005, 08:13 PM
steve_schefter@hotmail.com
Guest
 
Posts: n/a
Default Re: Problem with sockets

Hi Andrea.

> I'd like to know if there is a way to know if one of the sides of a

TCP
> connection is down without sending any message, using some API (in

UNIX)

It depends what you mean by "without sending any message". If you mean
from the application (so that you don't have to have a new message that
the remote will understand), then turn on TCP keepalives. A message is
sent, but it is sent by the stack and hidden from the apps.

For more details, search for "+so_keepalive +schefter" in google
groups.

Regards,
Steve

------------------------------------------------------------------------
Steve Schefter phone: +1 705 725 9999 x26
The Software Group Limited fax: +1 705 725 9666
642 Welham Road,
Barrie, Ontario CANADA L4N 9A1 Web: www.wanware.com

Reply With Quote
  #7  
Old 02-05-2005, 12:14 AM
Phil Frisbie, Jr.
Guest
 
Posts: n/a
Default Re: Problem with sockets

(E-Mail Removed) wrote:

> Hi Andrea.
>
>>I'd like to know if there is a way to know if one of the sides of a

> TCP
>>connection is down without sending any message, using some API (in

> UNIX)
>
> It depends what you mean by "without sending any message". If you mean
> from the application (so that you don't have to have a new message that
> the remote will understand), then turn on TCP keepalives. A message is
> sent, but it is sent by the stack and hidden from the apps.
>
> For more details, search for "+so_keepalive +schefter" in google
> groups.


However, note that TCP keepalives are depreciated, and by default they have a
time-out of 2 hours! Yes, you can change the time-out to something shorter, down
to seconds if you wish, but on most OSs this is a global setting, so it will
effect ALL TCP connections.


--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

Reply With Quote
Reply

Tags
problem, sockets

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
Forum Jump


All times are GMT. The time now is 07:27 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.