Re: How can I tell when a remote TCP connection is closed?
- From: "Alexander Nickolov" <agnickolov@xxxxxxxx>
- Date: Thu, 11 Aug 2005 09:42:01 -0700
Actually, recv won't fail - it will return zero bytes read for graceful
shutdown.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Phil Frisbie, Jr." <phil@xxxxxxxxxxxx> wrote in message
news:ee7CdRfnFHA.3448@xxxxxxxxxxxxxxxxxxxxxxx
> Jim H wrote:
>
>> I have a client with a TCP connection to a server. Without using events
>> (I need the code to be portable), is there a way that I can tell if the
>> remote end has closed the connection without performing a read or a write
>> on the socket? I tried doing a select for an error condition but it
>> times out. Select on readable or writeable always return as if the remote
>> end is still connected.
>
> select() on readable WILL return true if the server has closed the TCP
> connection gracefully, so perhaps you have something else wrong with your
> code?
>
>> The remote end is doing a shutdown and close on the socket. Netstat
>> shows close_wait. I need to know if the connection has been dropped
>> without having a read or write fail.
>
> After select() returns true for readable, then the recv() will fail with
> the error. That is the ONLY way to do it.
>
>> Can anyone help me out with this?
> >
>> Thanks in advance,
>> jim
>
> --
> Phil Frisbie, Jr.
> Hawk Software
> http://www.hawksoft.com
.
- References:
- How can I tell when a remote TCP connection is closed?
- From: Jim H
- Re: How can I tell when a remote TCP connection is closed?
- From: Phil Frisbie, Jr.
- How can I tell when a remote TCP connection is closed?
- Prev by Date: Re: getaddrinfo in XP,9x,etc - how?
- Next by Date: Re: getaddrinfo in XP,9x,etc - how?
- Previous by thread: Re: How can I tell when a remote TCP connection is closed?
- Next by thread: Re: How can I tell when a remote TCP connection is closed?
- Index(es):
Relevant Pages
|