Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19416

Re: detecting Socket disconnect

Newsgroups comp.lang.java.programmer
Date 2012-10-17 13:47 -0700
References <c46d29c6-f804-43da-b748-ef50c3a8bdfa@googlegroups.com>
Message-ID <8f8165f3-93a2-4922-8501-36e6f93c85c3@googlegroups.com> (permalink)
Subject Re: detecting Socket disconnect
From Lew <lewbloch@gmail.com>

Show all headers | View raw


bob smith wrote:
> I have a java.net.Socket that I only write to, and I can't figure out how to tell if it's disconnected.
> 
> I call socket.isConnected(), but it still returns true after I broke the TCP connection.  I had telnetted in thru Windows telnet and closed the window.

Closed what window?

How do you know that closing "the window" broke the connection?

What reads from the other end of the connection?

> Anyone know how to detect the disconnect?

http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#isConnected()
"Returns: true if the socket was successfuly connected to a server"

Your socket was connected, so according to the docs you should get 'true'.

What does 
http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#isClosed()
tell you?

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

detecting Socket disconnect bob smith <bob@coolfone.comze.com> - 2012-10-17 13:12 -0700
  Re: detecting Socket disconnect Arne Vajhoej <arne@vajhoej.dk> - 2012-10-17 16:45 -0400
  Re: detecting Socket disconnect Lew <lewbloch@gmail.com> - 2012-10-17 13:47 -0700
    Re: detecting Socket disconnect Arne Vajhoej <arne@vajhoej.dk> - 2012-10-17 17:19 -0400
  Re: detecting Socket disconnect Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-10-17 13:59 -0700
    Re: detecting Socket disconnect Arne Vajhoej <arne@vajhoej.dk> - 2012-10-17 17:24 -0400
      Re: detecting Socket disconnect Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-10-17 14:42 -0700
    Re: detecting Socket disconnect Steven Simpson <ss@domain.invalid> - 2012-10-18 09:31 +0100
      Re: detecting Socket disconnect Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-10-18 07:09 -0700
  Re: detecting Socket disconnect Martin Gregorie <martin@address-in-sig.invalid> - 2012-10-17 21:14 +0000
  Re: detecting Socket disconnect Roedy Green <see_website@mindprod.com.invalid> - 2012-10-17 15:52 -0700

csiph-web