[fixed]修复正在连接时断开失败问题,修复主动端看连接时固定IP轮序未停止问题

This commit is contained in:
xinfengkun
2022-03-03 16:28:58 +08:00
parent 2a71dd3ba6
commit ba720c405b
3 changed files with 41 additions and 23 deletions

View File

@@ -125,6 +125,14 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
}
}
@Override
public void onStopFindIP() {
if (adasConnectStatusListener != null) {
ipcConnectionStatus = Constants.IPC_CONNECTION_STATUS.DISCONNECTED;
adasConnectStatusListener.onConnectionIPCStatus(ipcConnectionStatus, null);
}
}
/**
* 可连通的IP
*
@@ -435,11 +443,10 @@ public class AdasChannel implements IAdasNetCommApi, FpgaSocket.IWebSocketConnec
*/
@Override
public void disconnect() {
if (ipcFixationIPHelper!=null){
ipcFixationIPHelper.stop();
}
if (!adasOptions.isClient()) {
// ipcConnectionStatus = Constants.IPC_CONNECTION_STATUS.DISCONNECTED;
// if (adasConnectStatusListener != null) {
// adasConnectStatusListener.onConnectionIPCStatus(ipcConnectionStatus, null);
// }
if (udpConstract != null)
udpConstract.release();
if (mSocket != null)

View File

@@ -35,6 +35,11 @@ public class IPCFixationIPHelper {
*/
void onStartFindIP();
/**
* 主动停止
*/
void onStopFindIP();
/**
* 轮询结果可连通的IP
*
@@ -54,6 +59,16 @@ public class IPCFixationIPHelper {
}
}
public void stop() {
if (retryTimer != null) {
retryTimer.cancel();
retryTimer = null;
}
isCallListener = true;
interrupted();
listener.onStopFindIP();
}
/**
* 开始根据固定IP列表惊醒PING 方式查找可用工控机
*/

View File

@@ -100,7 +100,7 @@ public class FpgaSocket implements IWebSocket {
request = new Request.Builder()
.url(wsHost)
.build();
client.newWebSocket(request, listener);
mWebSocket = client.newWebSocket(request, listener);
}
}
@@ -257,30 +257,14 @@ public class FpgaSocket implements IWebSocket {
public void onClosing(@NonNull WebSocket webSocket, int code, @NonNull String reason) {
super.onClosing(webSocket, code, reason);
CupidLogUtils.e(TAG, "WebSocket onClosing= " + reason);
if (mWebSocket != null) {
mWebSocket.close(1000, null);
mWebSocket.cancel();
mWebSocket = null;
} else {
if (mWebSocketConnectListener != null)
mWebSocketConnectListener.onWebSocketConnectFailed(reason);
reconnect();
}
onClose(reason);
}
@Override
public void onClosed(@NonNull WebSocket webSocket, int code, @NonNull String reason) {
super.onClosed(webSocket, code, reason);
CupidLogUtils.e(TAG, "WebSocket onClosed= " + reason);
if (mWebSocket != null) {
mWebSocket.close(1000, null);
mWebSocket.cancel();
mWebSocket = null;
} else {
if (mWebSocketConnectListener != null)
mWebSocketConnectListener.onWebSocketConnectFailed(reason);
reconnect();
}
onClose(reason);
}
@Override
@@ -299,6 +283,18 @@ public class FpgaSocket implements IWebSocket {
}
}
private void onClose(String reason) {
if (mWebSocket != null) {
mWebSocket.close(1000, null);
mWebSocket.cancel();
mWebSocket = null;
} else {
if (mWebSocketConnectListener != null)
mWebSocketConnectListener.onWebSocketConnectFailed(reason);
reconnect();
}
}
public WebSocket getWebSocket() {
return mWebSocket;
}