Skip to content

Commit 7975676

Browse files
committed
修改因过期时间太短,导致时间戳过期发生断开问题
1 parent e55ff09 commit 7975676

File tree

1 file changed

+6
-7
lines changed
  • explorer/explorer-device-android/src/main/java/com/tencent/iot/explorer/device/android/mqtt

1 file changed

+6
-7
lines changed

explorer/explorer-device-android/src/main/java/com/tencent/iot/explorer/device/android/mqtt/TXMqttConnection.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class TXMqttConnection extends com.tencent.iot.hub.device.java.core.mqtt.
5050

5151
protected TXAlarmPingSender mPingSender = null;
5252

53+
private long mExpiredTime = Integer.MAX_VALUE;
5354

5455
/**
5556
* @param context 用户上下文(这个参数在回调函数时透传给用户)
@@ -206,6 +207,10 @@ private String sign(String src, String psk) {
206207
return null;
207208
}
208209

210+
public void setExpiredTime(long expiredTime) {
211+
this.mExpiredTime = Math.max(expiredTime, System.currentTimeMillis() / 1000 + 600);
212+
}
213+
209214
/**
210215
* 连接 MQTT 服务器,结果通过回调函数通知,无需设置 username 和 password,内部会自动填充
211216
*
@@ -230,13 +235,7 @@ public synchronized Status connect(MqttConnectOptions options, Object userContex
230235
return Status.PARAMETER_INVALID;
231236
}
232237

233-
Long timestamp;
234-
if (options.isAutomaticReconnect()) {
235-
timestamp = (long) Integer.MAX_VALUE;
236-
} else {
237-
timestamp = System.currentTimeMillis()/1000 + 600;
238-
}
239-
String userNameStr = mUserName + ";" + getConnectId() + ";" + timestamp;
238+
String userNameStr = mUserName + ";" + getConnectId() + ";" + mExpiredTime;
240239

241240
mConnOptions.setUserName(userNameStr);
242241

0 commit comments

Comments
 (0)