|
|
|
@ -1,6 +1,9 @@ |
|
|
|
package com.inspect.tcpserver.tcp; |
|
|
|
|
|
|
|
import com.inspect.tcpserver.util.Color; |
|
|
|
import io.netty.buffer.ByteBuf; |
|
|
|
import io.netty.buffer.Unpooled; |
|
|
|
import io.netty.channel.ChannelFuture; |
|
|
|
import io.netty.channel.ChannelHandlerContext; |
|
|
|
import io.netty.channel.ChannelInboundHandlerAdapter; |
|
|
|
import io.netty.channel.EventLoop; |
|
|
|
@ -30,9 +33,16 @@ public class NettyClientHandler extends ChannelInboundHandlerAdapter { |
|
|
|
|
|
|
|
public void sendProtoBuffer(ByteBuf byteBuf) { |
|
|
|
if (clientChannelHandlerContext != null) { |
|
|
|
clientChannelHandlerContext.writeAndFlush(byteBuf); |
|
|
|
clientChannelHandlerContext.writeAndFlush(Unpooled.wrappedBuffer(byteBuf)).addListener( |
|
|
|
(ChannelFuture future) -> { |
|
|
|
if (future.isSuccess()) { |
|
|
|
log.info(Color.CYAN + "###### 向上级系统发送消息成功 ######" + Color.END); |
|
|
|
} else { |
|
|
|
log.info(Color.RED + "###### 向上级系发送消息失败 ######" + Color.END); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
log.info("client发送消息时,content为空,未连接服务端,取消发送"); |
|
|
|
log.info(Color.RED + "###### 无法向上级系发送消息,ctx==null ######" + Color.END); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|