/**
* 如果关键字状态为可写,则也说明Channel是一个客户端的连接通道,
* 进行相应的向客户端写数据的操作
*/
if(key.isWritable())
{
doClinetWriteEvent(key);
continue;
}
}
}
}
/**
* 处理服务器事件操作
* @param key 服务器选择键对象
*/
private void doServerSocketEvent(SelectionKey key)
{
SocketChannel client=null;
try
{
ServerSocketChannel server=(ServerSocketChannel)key.channel();
client=server.accept();
if(client==null)
{
return;
}
client.configureBlocking(false);//将客户端Channel设置为非阻塞型
/**
/**
* 将客户端Channel注册到Selector对象上,并且指出客户端Channel所感兴趣的事件为可读和可写
*/
client.register(selector,SelectionKey.OP_READ|SelectionKey.OP_READ);
}catch(IOException e)