My server uses AsynchronousServerSocketChannel , which listens for client connections using CompletionHandler . When a client connection is accepted, AsynchronousSocketChannel read, again using the CompletionHandler to receive data without a timeout.
It is still so good, my client connects, writes data that the server reads, which can respond to sending data back to the client through the same socket.
When my client shuts down, it calls AsynchronousSocketChannel.close() to close the socket. When this call is made, the server waits to read data from the socket.
I expected the call to AsynchronousSocketChannel.close() on the client to translate to a callback to CompletionHandler.completed with a read length of -1 on the server, indicating that the socket was closed, however the callback is CompletionHandler.failed with the following exception:
java.io.IOException: The specified network name is no longer available. at sun.nio.ch.Iocp.translateErrorToIOException(Iocp.java:309) at sun.nio.ch.Iocp.access$700(Iocp.java:46) at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:399) at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:744)
How should the client close the socket so that it is not considered a server error?
java nio nio2
Nick holt
source share