Class NioQuickClient

java.lang.Object
org.aoju.bus.socket.NioQuickClient
All Implemented Interfaces:
Closeable, AutoCloseable

public class NioQuickClient extends Object implements Closeable
NIO客户端
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • NioQuickClient

      public NioQuickClient(String host, int port)
      构造
      Parameters:
      host - 服务器地址
      port - 端口
    • NioQuickClient

      public NioQuickClient(InetSocketAddress address)
      构造
      Parameters:
      address - 服务器地址
  • Method Details

    • init

      public NioQuickClient init(InetSocketAddress address)
      初始化
      Parameters:
      address - 地址和端口
      Returns:
      this
    • setChannelHandler

      public NioQuickClient setChannelHandler(ChannelSocketHandler handler)
      设置NIO数据处理器
      Parameters:
      handler - ChannelSocketHandler
      Returns:
      this
    • listen

      public void listen()
      开始监听
    • write

      public NioQuickClient write(ByteBuffer... datas)
      实现写逻辑 当收到写出准备就绪的信号后,回调此方法,用户可向客户端发送消息
      Parameters:
      datas - 发送的数据
      Returns:
      this
    • getChannel

      public SocketChannel getChannel()
      获取SocketChannel
      Returns:
      SocketChannel
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable