|
@@ -2,6 +2,8 @@ package com.wdkl.ncs.android.middleware.tcp;
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
+import com.wdkl.ncs.android.component.nursehome.common.Constants;
|
|
|
+
|
|
|
import java.util.Scanner;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
@@ -59,7 +61,7 @@ public class TcpClient {
|
|
|
// LengthFieldPrepender是一个编码器,主要是在响应字节数据前面添加字节长度字段
|
|
|
socketChannel.pipeline().addLast(new LengthFieldPrepender(2));
|
|
|
//心跳包应当小于服务器间隔
|
|
|
- socketChannel.pipeline().addLast(new IdleStateHandler(0, hbSeconds, 0, TimeUnit.SECONDS));
|
|
|
+ socketChannel.pipeline().addLast(new IdleStateHandler(hbSeconds+1, hbSeconds, 0, TimeUnit.SECONDS));
|
|
|
socketChannel.pipeline().addLast(new StringDecoder(CharsetUtil.UTF_8));
|
|
|
socketChannel.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8));
|
|
|
socketChannel.pipeline().addLast(tcpClientHandler);
|
|
@@ -93,8 +95,8 @@ public class TcpClient {
|
|
|
if (retryTimes > 30) {
|
|
|
System.out.println("TcpClient 重试" + (retryTimes - 1) + "次,结束");
|
|
|
workGroup.shutdownGracefully();
|
|
|
- //todo: 从API获取新的serverIP和serverPort,全新连接
|
|
|
- //TcpClient.getInstance().init();
|
|
|
+ //从API获取新的serverIP和serverPort,全新连接
|
|
|
+ TcpClient.getInstance().init(Constants.Companion.getTcp_server(), Constants.Companion.getTcp_port(), Constants.Companion.getHeart_beat());
|
|
|
return;
|
|
|
}
|
|
|
doConnect();
|