public abstract class NioServer extends Object implements Closeable
| Constructor and Description |
|---|
NioServer(int port)
构造
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
NioServer |
init(InetSocketAddress address)
初始化
|
void |
listen()
开始监听
|
protected abstract void |
read(SocketChannel socketChannel)
处理读事件
当收到读取准备就绪的信号后,回调此方法,用户可读取从客户端传世来的消息
|
protected abstract void |
write(SocketChannel socketChannel)
实现写逻辑
当收到写出准备就绪的信号后,回调此方法,用户可向客户端发送消息
|
public NioServer init(InetSocketAddress address)
address - 地址和端口public void listen()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionprotected abstract void read(SocketChannel socketChannel)
socketChannel - SocketChannelprotected abstract void write(SocketChannel socketChannel)
socketChannel - SocketChannelCopyright © 2019. All rights reserved.