Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #19422
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: detecting Socket disconnect |
| Date | 2012-10-17 21:14 +0000 |
| Organization | UK Free Software Network |
| Message-ID | <k5n73l$rk3$1@localhost.localdomain> (permalink) |
| References | <c46d29c6-f804-43da-b748-ef50c3a8bdfa@googlegroups.com> |
On Wed, 17 Oct 2012 13:12:13 -0700, 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. > > Anyone know how to detect the disconnect? > The most you can do is enable S_KEEPALIVE by calling Socket.setKeepAlive (). This causes the TCP/IP stack to send a periodic system message to check whether the connection is still there. However, this is fairly useless because the default keepalive frequency can be as slow as once every two hours (it says) and there's no Java method that can change that frequency. As a result TCP/IP doesn't notice a broken connection until you try to send a message over it. About the best you can do is arrange for the client to exchange an 'are you still there/yes I am' message pair with the server at intervals when the connection is idle. This makes TCP/IP somewhat deficient for some tasks, e.g. running an ATM network since, unless each ATM polls the server fairly frequently its likely to say its in service until the punter sticks his card in and enters his PIN - that's when the first message is sent to the bank's server and so, without a fairly frequent 'Im alive, are you' poll, thats when the ATM discovers the line or server is dead and pisses off the punter by putting up its OUT OF ORDER display and giving his card back. It explains why X.25, which instantly notices disconnects of endpoint failures and notified both endpoints of the failure, is/was so popular for ATM networks. Even the much older proprietary polled network protocols such as SNA and 3270 Bisync, will notice a network failure pretty much instantly: as soon as a poll goes unanswered the system knows something has broken, and these protocols polled their terminals several times a second. HTH -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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