ServerSocketChannel acceptorSvr = ServerSocketChannel.open();
acceptorSvr.socket().bind(new InetSocketAddress(InetAddress.getByName("IP"),port));
acceptorSvr.configureBlocking(false);
Selector selector = Selector.open();
New Thread(new ReactorTask()).start();
SelectionKey key = acceptorSvr.register(selector,SelectionKey.OP_ACCEPt,ioHandler);
int num = selector.select();
Set selectedKeys = selector.selectedKeys();
Iterator it = selectedKeys.iterator();
while(it.hasNext()){
SelectionKey key = (SelectionKey)it.next();
}
SocketChannel channel = svrChannel.accept();
channel.configureBlocking(false);
channel.socket().setReuseAddress(true);
SelectionKey key = socketChannel.register(selector,SelectionKey.OP_READ,ioHandler);
int readNumber = channel.read(receivedBuffer);
Object message = null;
while(buffer.hasRemain()){
byteBuffer.mark();
Object message = decode(byteBuffer);
if(message == null){
byteBuffer.reset();
break;
}
messageList.add(message);
}
if(!byteBuffer.hasRemain()){
byteBuffer.clear();
}else{
byteBuffer.compact();
}
if(messageList !=null &!messageList.isEmpty()){
for(Object messageE : messageList){
handlerTask(messageE);
}
}
socketChannel.write(buffer);