public class NioBlockingEchoServer { public static void main(String[] args) throws IOException { ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.bind(new InetSocketAddress("localhost", 7000)); while (active) { SocketChannel socketChannel = serverSocketChannel.accept(); // blocking ByteBuffer buffer = ByteBuffer.allocate(1024); while (true) { buffer.clear(); int read = socketChannel.read(buffer); // blocking if (read < 0) { break; } buffer.flip(); socketChannel.write(buffer); // blocking } socketChannel.close(); } serverSocketChannel.close(); } }