import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
public class NIOTest {
public static void main(String[] args) throws Exception {
ServerSocketChannel server = ServerSocketChannel.open();
server.bind(null);
SocketAddress saddr = server.getLocalAddress();
SocketChannel client = SocketChannel.open(saddr);
System.out.println(client);
client.close();
ByteBuffer buf = ByteBuffer.wrap("Hello world".getBytes());
client.write(buf);
}
}
throws AsynchronousCloseException instead of ChannelClosedException