Skip to content
Search

Java.net.Socket

lastmod 2018-08-17created 2014-06-033 edits

Notes on Java socket communication.

How to terminate a thread blocking on socket IO operation instantly

There are two ways to do this:

  • Calling Thread.interrupt() will (under some circumstances that are not specified) interrupt a blocking I/O operation, causing it to throw an InterruptedIOException or ClosedByInterruptException.
  • Calling Socket.close() on the socket will close the associated InputStream and OutputStream objects, and cause any threads blocked in Socket or (associated) stream operations to be unblocked. According to the javadoc, operations on the socket itself will throw a SocketException.

See also

Favorite site

References


  1. Java_socket_programming_example.pdf ↩

  2. Zerioh_tripod_com-Java_Sockets_Example.zip ↩

  3. Www.javacool.net.zip (see www.javacool.net/_cool/api_doc/kor_jdk11api/java.net.Socket_dsc.htm) ↩

  4. Java_socket_timeout.pdf ↩

  5. Xrath_com-java-spec.zip (see xrath.com/javase/ko/6/docs/ko/api/java/net/Socket.html) ↩

  6. Java_stream_and_socket.pdf ↩