|
||||||||
|
|
#1
|
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
<(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* |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
"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 |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
(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 |
![]() |
| Tags |
| problem, sockets |
| Thread Tools | |
| Display Modes | |
|
|