mirror of
https://github.com/WuKongIM/WuKongIMAndroidSDK
synced 2025-06-06 17:50:53 +00:00
fix:update connection
This commit is contained in:
parent
5e507404b2
commit
19a5b5f207
@ -6,8 +6,8 @@ import com.xinbida.wukongim.WKIM;
|
||||
import com.xinbida.wukongim.WKIMApplication;
|
||||
import com.xinbida.wukongim.interfaces.IConnectionStatus;
|
||||
import com.xinbida.wukongim.interfaces.IGetIpAndPort;
|
||||
import com.xinbida.wukongim.message.WKConnection;
|
||||
import com.xinbida.wukongim.message.MessageHandler;
|
||||
import com.xinbida.wukongim.message.WKConnection;
|
||||
import com.xinbida.wukongim.utils.WKLoggerUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -91,7 +91,7 @@ public class WKConnection {
|
||||
private String lastRequestId;
|
||||
private int unReceivePongCount = 0;
|
||||
public volatile Handler reconnectionHandler = new Handler(Objects.requireNonNull(Looper.myLooper()));
|
||||
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
// private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
Runnable reconnectionRunnable = this::reconnection;
|
||||
private int connCount = 0;
|
||||
|
||||
@ -166,6 +166,7 @@ public class WKConnection {
|
||||
closeConnect();
|
||||
socketSingleID = UUID.randomUUID().toString().replace("-", "");
|
||||
connectionClient = new ConnectionClient(iNonBlockingConnection -> {
|
||||
connCount = 0;
|
||||
if (iNonBlockingConnection == null || connection == null || !connection.getId().equals(iNonBlockingConnection.getId())) {
|
||||
forcedReconnection();
|
||||
return;
|
||||
@ -508,23 +509,18 @@ public class WKConnection {
|
||||
}
|
||||
|
||||
private synchronized void closeConnect() {
|
||||
mainHandler.post(() -> {
|
||||
if (connection != null && connection.isOpen()) {
|
||||
try {
|
||||
WKLoggerUtils.getInstance().e("stop connection:" + connection.getId());
|
||||
if (connection != null && connection.isOpen()) {
|
||||
try {
|
||||
WKLoggerUtils.getInstance().e("stop connection:" + connection.getId());
|
||||
// connection.flush();
|
||||
connection.setAttachment("close" + connection.getId());
|
||||
connection.close();
|
||||
} catch (IOException e) {
|
||||
WKLoggerUtils.getInstance().e("stop connection IOException" + e.getMessage());
|
||||
} finally {
|
||||
connection = null;
|
||||
}
|
||||
|
||||
connection.setAttachment("close" + connection.getId());
|
||||
connection.close();
|
||||
} catch (IOException e) {
|
||||
WKLoggerUtils.getInstance().e("stop connection IOException" + e.getMessage());
|
||||
} finally {
|
||||
connection = null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Timer checkNetWorkTimer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user