Skip to content

Commit 88f4e11

Browse files
committed
1 parent 65c96d7 commit 88f4e11

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

netty-android/src/main/java/com/goav/netty/Handler/Client.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ protected void initChannel(SocketChannel ch) throws Exception {
108108
socketChannel = (SocketChannel) future.channel();
109109
logger.info("socketChannel连接成功");
110110
} else {
111+
try {
112+
//预防连接数超出系统上线
113+
future.channel().disconnect();
114+
future.channel().close();
115+
eventLoopGroup.rebuildSelectors();
116+
} catch (Exception e) {
117+
118+
}
111119
throw new InterruptedException("connection fail.");
112120
}
113121
} catch (Exception e) {
@@ -156,7 +164,7 @@ public boolean getConnectState() {
156164
@Override
157165
protected void restart(boolean restart) {
158166
reset();
159-
if (!getConnectState() && restart && !onDestrOY) {
167+
if (!getConnectState() && restart && !onDestrOY && ClientNetWork.newInstance().isNetworkAvailable()) {
160168
reset2Connect();
161169
}
162170
}

netty-android/src/main/java/com/goav/netty/Handler/ClientNetWork.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private void initThread() {
2323
public void run() {
2424
while (callBack != null && mContext != null) {
2525
try {
26-
Thread.sleep(3000);
26+
Thread.sleep(5000);
2727
} catch (InterruptedException e) {
2828
e.printStackTrace();
2929
}
@@ -63,7 +63,7 @@ private void pushNetWorkState() {
6363
}
6464
}
6565

66-
private boolean isNetworkAvailable() {
66+
public boolean isNetworkAvailable() {
6767
if (mContext == null) {
6868
isConnect = false;
6969
return false;

0 commit comments

Comments
 (0)