Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38973
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2019-05-29 08:22 -0700 |
| References | <slrnqespnm.cfl.avl@logic.at> <1v9ncmqz4ep4j$.1mdftm8twalol$.dlg@40tude.net> <slrnqet716.cfl.avl@logic.at> |
| Message-ID | <afae8c57-f998-433a-84fa-16b64b400185@googlegroups.com> (permalink) |
| Subject | Re: server-side Socket does not recognize broken connection. |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Wednesday, May 29, 2019 at 10:50:25 AM UTC-4, Andreas Leitgeb wrote: > A separate thread to read blockingly and shovel the results into a > Queue (as Eric suggested) is plausible, assuming that it works. The SocketServer has the setSoTimeout() method to tell it how long to listen for the client connection on the accept() method. This method returns an instance of Socket which is connected to a client instance of Socket. The Socket class also has setSoTimeout, so this can be called from client and/or server. "Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout." So it seems zero is the default timeout, which should throw a timeout exception based on when the OS says a socket is timed out, checking available will tell you if there's any data to be read on the socket but won't tell you if the other end is still connected, attempting to read the socket will grab any data and throw an exception if the other side is disconnected, the read attempt will wait and block for the length of time set by the timeout method, and if you have reason to not block the socket you'll need a secondary method to determine if the other side is still active.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2019-05-29 11:03 +0000
Re: server-side Socket does not recognize broken connection. Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-05-29 08:30 -0400
Re: server-side Socket does not recognize broken connection. Joerg Meier <joergmmeier@arcor.de> - 2019-05-29 14:58 +0200
Re: server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2019-05-29 14:50 +0000
Re: server-side Socket does not recognize broken connection. Eric Douglas <e.d.programmer@gmail.com> - 2019-05-29 08:22 -0700
Re: server-side Socket does not recognize broken connection. Andreas Leitgeb <avl@logic.at> - 2020-01-30 15:22 +0000
Re: server-side Socket does not recognize broken connection. Martin Gregorie <martin@mydomain.invalid> - 2019-05-29 16:06 +0000
Re: server-side Socket does not recognize broken connection. Eric Douglas <e.d.programmer@gmail.com> - 2019-05-29 07:14 -0700
Re: server-side Socket does not recognize broken connection. trisha guillot <guillottrisha347@gmail.com> - 2019-05-31 20:13 -0700
Re: server-side Socket does not recognize broken connection. Marcel Mueller <news.5.maazl@spamgourmet.org> - 2019-06-01 16:08 +0200
csiph-web