Package org.aoju.bus.socket
Class NioQuickClient
java.lang.Object
org.aoju.bus.socket.NioQuickClient
- All Implemented Interfaces:
Closeable,AutoCloseable
NIO客户端
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionNioQuickClient(String host, int port) 构造NioQuickClient(InetSocketAddress address) 构造 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()获取SocketChannelinit(InetSocketAddress address) 初始化voidlisten()开始监听setChannelHandler(ChannelSocketHandler handler) 设置NIO数据处理器write(ByteBuffer... datas) 实现写逻辑 当收到写出准备就绪的信号后,回调此方法,用户可向客户端发送消息
-
Constructor Details
-
NioQuickClient
构造- Parameters:
host- 服务器地址port- 端口
-
NioQuickClient
构造- Parameters:
address- 服务器地址
-
-
Method Details
-
init
初始化- Parameters:
address- 地址和端口- Returns:
- this
-
setChannelHandler
设置NIO数据处理器- Parameters:
handler-ChannelSocketHandler- Returns:
- this
-
listen
public void listen()开始监听 -
write
实现写逻辑 当收到写出准备就绪的信号后,回调此方法,用户可向客户端发送消息- Parameters:
datas- 发送的数据- Returns:
- this
-
getChannel
获取SocketChannel- Returns:
- SocketChannel
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-