1. // 启动监听和链接
    2. ChannelFuture channelFuture = bootstrap.connect(ip, port).sync();
    3. if (channelFuture.isSuccess()) {
    4. System.out.println("链接server 成功");
    5. }
    6. channelFuture.channel().closeFuture().sync();
    1. channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
    2. @Override
    3. public void operationComplete(ChannelFuture f) throws Exception {
    4. if (f.isSuccess()) {
    5. responseFuture.setSendRequestOK(true);
    6. return;
    7. } else {
    8. responseFuture.setSendRequestOK(false);
    9. }
    10. responseTable.remove(opaque);
    11. responseFuture.setCause(f.cause());
    12. responseFuture.putResponse(null);
    13. log.warn("send a request command to channel <" + addr + "> failed.");
    14. }
    15. });

    这里是要主动发送对应的数据的