diff --git a/src/main/java/com/msb/io/nio/Server.java b/src/main/java/com/msb/io/nio/Server.java index 30be4ea..6f849cd 100644 --- a/src/main/java/com/msb/io/nio/Server.java +++ b/src/main/java/com/msb/io/nio/Server.java @@ -7,6 +7,7 @@ package com.msb.io.nio;/** import java.io.IOException; import java.net.InetSocketAddress; +import java.net.ServerSocket; import java.nio.ByteBuffer; import java.nio.channels.*; import java.util.Iterator; @@ -47,9 +48,14 @@ public class Server { private static void handle(SelectionKey key) throws IOException { if(key.isAcceptable()) { - ServerSocketChannel ssc = (ServerSocketChannel) key.channel(); + /*ServerSocketChannel ssc = (ServerSocketChannel) key.channel(); ssc.configureBlocking(false); - ssc.register(key.selector(), SelectionKey.OP_READ); + ssc.register(key.selector(), SelectionKey.OP_READ);*/ + ServerSocketChannel ssc = (ServerSocketChannel) key.channel(); + SocketChannel sc = ssc.accept(); + sc.configureBlocking(false); + sc.register(key.selector(), SelectionKey.OP_READ); + } else if(key.isReadable()) { SocketChannel sc = (SocketChannel) key.channel(); ByteBuffer buffer = ByteBuffer.allocate(512);