1、修改TCP推送的bug
This commit is contained in:
parent
d7bb69c185
commit
b85daf498d
@ -34,7 +34,7 @@ public class TCPClient {
|
||||
public void init(String dest_addr, int dest_port) {
|
||||
host = dest_addr;
|
||||
port = dest_port;
|
||||
sendBuffer = Unpooled.buffer();
|
||||
|
||||
//客户端需要一个事件循环组
|
||||
group = new NioEventLoopGroup();
|
||||
//创建客户端启动对象
|
||||
@ -83,6 +83,7 @@ public class TCPClient {
|
||||
}
|
||||
|
||||
public void writeAndFlush(String json) {
|
||||
sendBuffer = Unpooled.buffer();
|
||||
sendBuffer.writeBytes(json.getBytes(StandardCharsets.UTF_8));
|
||||
if(channel.isActive()) flush();
|
||||
else connect();
|
||||
@ -97,7 +98,7 @@ public class TCPClient {
|
||||
channel.writeAndFlush(sendBuffer).addListener(future -> {
|
||||
if (future.isSuccess()) {
|
||||
logger.info("send to xfz server succeed.");
|
||||
sendBuffer.clear();
|
||||
sendBuffer.release();
|
||||
} else {
|
||||
logger.info("send to xfz server failed.");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user