Re: How can I tell when a remote TCP connection is closed?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks for the replies. I'm using select to see if a socket is readable and
calling recv to see if it returns 0. Recv only returns zero if the peer has
gracefully shut the connection down. My problem is non-graceful
disconnects. I'm getting times where my recv returns a byte but when I go
to write to the socket and I get an broken pipe error. How do I detect non
graceful disconnects? Will exception fds passed to select be set int these
instances? I'm putting the code in to try it but I have to wait for a
broken pipe to happen, so if someone knows the answer I'd appreciate it.

Thanks in advance,
jim

"Jim H" <jimh@xxxxxxxxxxxxx> wrote in message
news:ObYSn0enFHA.576@xxxxxxxxxxxxxxxxxxxxxxx
>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.
>
> 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.
>
> Can anyone help me out with this?
>
> Thanks in advance,
> jim
>


.



Relevant Pages

  • Re: How to tell when a socket is closed on the other end?
    ... remote server is behaving properly by closing a socket from the server side ... preferably determine if it was closed from the remote end as expected. ... All you know is that the connection did indeed get shut down. ... The SMTP user-level protocol sent "221 Bye", then, my telnet client saw the ...
    (comp.lang.python)
  • Re: SOCKET_ERROR [10054]
    ... using SocketWrench .net component. ... connection was forcibly closed by the remote host. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: getting client ip in sock-client on server
    ... getsockname using PInvoke mechanism. ... will give you the remote address and getsockname will give you the local ... address for the connection. ... socket handle and pass it into these API as parameters. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Tcp Sockets Close event
    ... in the old vb6 winsock object there was an Event raised when the remote side ... Closed the socket connection, ... > into the sample code to see how we handle the events generally. ...
    (microsoft.public.dotnet.academic)
  • Re: Unicast UDP Server
    ... when binding the socket. ... You're trying to bind your local socket to a remote address. ... But that would require the remote connection to be Bound to that port ...
    (microsoft.public.dotnet.languages.csharp)