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
- Java socket communication example 1
- [Recommended] Stackoverflow: How to have multiple clients connect to a server java: Plain Thread Example
- Java Sockets Example 2
- Class java.net.Socket (Korean) 3
- Timeout for JAVA socket connections 4
- Class java.net.Socket (Korean) 5
- Stream and Socket 6
References
-
Java_socket_programming_example.pdf ↩
-
Zerioh_tripod_com-Java_Sockets_Example.zip ↩
-
Www.javacool.net.zip (see
www.javacool.net/_cool/api_doc/kor_jdk11api/java.net.Socket_dsc.htm) ↩ -
Java_socket_timeout.pdf ↩
-
Xrath_com-java-spec.zip (see
xrath.com/javase/ko/6/docs/ko/api/java/net/Socket.html) ↩ -
Java_stream_and_socket.pdf ↩