public abstract class NioServer
extends java.lang.Object
implements java.io.Closeable
| 构造器和说明 |
|---|
NioServer(int port)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
NioServer |
init(java.net.InetSocketAddress address)
初始化
|
void |
listen()
开始监听
|
protected abstract void |
read(java.nio.channels.SocketChannel socketChannel)
处理读事件
当收到读取准备就绪的信号后,回调此方法,用户可读取从客户端传世来的消息 |
protected abstract void |
write(java.nio.channels.SocketChannel socketChannel)
实现写逻辑
当收到写出准备就绪的信号后,回调此方法,用户可向客户端发送消息 |
public NioServer init(java.net.InetSocketAddress address)
address - 地址和端口public void listen()
public void close()
throws java.io.IOException
close 在接口中 java.io.Closeableclose 在接口中 java.lang.AutoCloseablejava.io.IOExceptionprotected abstract void read(java.nio.channels.SocketChannel socketChannel)
socketChannel - SocketChannelprotected abstract void write(java.nio.channels.SocketChannel socketChannel)
socketChannel - SocketChannelCopyright © 2019. All rights reserved.