1、增加TCP连接过程打印,以便查看连接失败原因
This commit is contained in:
parent
cef333b56b
commit
87d6f6073d
@ -54,7 +54,7 @@ public class TCPClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void connect() {
|
public void connect() {
|
||||||
logger.info("netty client starting");
|
logger.info("{}:{} tcp connecting...",host,port);
|
||||||
//启动客户端去连接服务器端
|
//启动客户端去连接服务器端
|
||||||
try {
|
try {
|
||||||
ChannelFuture cf = bootstrap.connect(host, port);
|
ChannelFuture cf = bootstrap.connect(host, port);
|
||||||
@ -62,9 +62,10 @@ public class TCPClient {
|
|||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
if (!future.isSuccess()) {
|
if (!future.isSuccess()) {
|
||||||
|
logger.info("{}:{} tcp connect failed",host,port);
|
||||||
//重连交给后端线程执行
|
//重连交给后端线程执行
|
||||||
future.channel().eventLoop().schedule(() -> {
|
future.channel().eventLoop().schedule(() -> {
|
||||||
logger.info("tcp client reconnect");
|
logger.info("{}:{} tcp client reconnect",host,port);
|
||||||
try {
|
try {
|
||||||
connect();
|
connect();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -72,7 +73,7 @@ public class TCPClient {
|
|||||||
}
|
}
|
||||||
}, 5000, TimeUnit.MILLISECONDS);
|
}, 5000, TimeUnit.MILLISECONDS);
|
||||||
} else {
|
} else {
|
||||||
logger.info("tcp client start success!");
|
logger.info("{}:{} tcp client start success!",host,port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -80,7 +81,7 @@ public class TCPClient {
|
|||||||
this.channel = cf.channel();
|
this.channel = cf.channel();
|
||||||
this.channel.closeFuture().sync();
|
this.channel.closeFuture().sync();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("netty client error:", e);
|
logger.error(host+":"+port+" tcp connect error:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user