public class NioClient extends Object implements Closeable
Constructor and Description |
---|
NioClient(InetSocketAddress address)
构造
|
NioClient(String host,
int port)
构造
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
SocketChannel |
getChannel()
获取SocketChannel
|
NioClient |
init(InetSocketAddress address)
初始化
|
void |
listen()
开始监听
|
NioClient |
setChannelHandler(ChannelHandler handler)
设置NIO数据处理器
|
NioClient |
write(ByteBuffer... datas)
实现写逻辑
当收到写出准备就绪的信号后,回调此方法,用户可向客户端发送消息 |
public NioClient(String host, int port)
host
- 服务器地址port
- 端口public NioClient(InetSocketAddress address)
address
- 服务器地址public NioClient init(InetSocketAddress address)
address
- 地址和端口public NioClient setChannelHandler(ChannelHandler handler)
handler
- ChannelHandler
public void listen()
public NioClient write(ByteBuffer... datas)
datas
- 发送的数据public SocketChannel getChannel()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2024. All rights reserved.