|
@@ -47,8 +47,7 @@ public class TcpClient {
|
|
//初始化Netty Tcp Client 并连接
|
|
//初始化Netty Tcp Client 并连接
|
|
public synchronized void init(String serverIP, Integer serverPort, Integer heartBeatSeconds, ITcpCallBack iTcpCallBack) {
|
|
public synchronized void init(String serverIP, Integer serverPort, Integer heartBeatSeconds, ITcpCallBack iTcpCallBack) {
|
|
if (bootstrap!=null){
|
|
if (bootstrap!=null){
|
|
- doConnect(iTcpCallBack);
|
|
|
|
- return;
|
|
|
|
|
|
+ bootstrap = null;
|
|
}
|
|
}
|
|
|
|
|
|
final Integer hbSeconds = heartBeatSeconds;
|
|
final Integer hbSeconds = heartBeatSeconds;
|
|
@@ -99,6 +98,7 @@ public class TcpClient {
|
|
} else {
|
|
} else {
|
|
//连接失败时的处理
|
|
//连接失败时的处理
|
|
System.out.println("TcpClient connect retry : " + retryTimes);
|
|
System.out.println("TcpClient connect retry : " + retryTimes);
|
|
|
|
+
|
|
channelFuture.channel().eventLoop().schedule(new Runnable() {
|
|
channelFuture.channel().eventLoop().schedule(new Runnable() {
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
@@ -110,12 +110,12 @@ public class TcpClient {
|
|
public void run() {
|
|
public void run() {
|
|
retryTimes = 0;
|
|
retryTimes = 0;
|
|
System.out.println("TcpClient 1分钟后 重试连接");
|
|
System.out.println("TcpClient 1分钟后 重试连接");
|
|
- doConnect(iTcpCallBack);
|
|
|
|
|
|
+ init(Constants.Companion.getTcpServer(),Constants.Companion.getTcpPort(),Constants.Companion.getHeartBeat(),iTcpCallBack);
|
|
}
|
|
}
|
|
},60*10, TimeUnit.SECONDS);
|
|
},60*10, TimeUnit.SECONDS);
|
|
} else {
|
|
} else {
|
|
retryTimes++;
|
|
retryTimes++;
|
|
- doConnect(iTcpCallBack);
|
|
|
|
|
|
+ init(Constants.Companion.getTcpServer(),Constants.Companion.getTcpPort(),Constants.Companion.getHeartBeat(),iTcpCallBack);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}, retrySeconds, TimeUnit.SECONDS);
|
|
}, retrySeconds, TimeUnit.SECONDS);
|