Skip to content

Commit

Permalink
修改因过期时间太短,导致时间戳过期发生断开问题
Browse files Browse the repository at this point in the history
  • Loading branch information
neilyhe committed Sep 13, 2024
1 parent e55ff09 commit 7975676
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class TXMqttConnection extends com.tencent.iot.hub.device.java.core.mqtt.

protected TXAlarmPingSender mPingSender = null;

private long mExpiredTime = Integer.MAX_VALUE;

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

public void setExpiredTime(long expiredTime) {
this.mExpiredTime = Math.max(expiredTime, System.currentTimeMillis() / 1000 + 600);
}

/**
* 连接 MQTT 服务器,结果通过回调函数通知,无需设置 username 和 password,内部会自动填充
*
Expand All @@ -230,13 +235,7 @@ public synchronized Status connect(MqttConnectOptions options, Object userContex
return Status.PARAMETER_INVALID;
}

Long timestamp;
if (options.isAutomaticReconnect()) {
timestamp = (long) Integer.MAX_VALUE;
} else {
timestamp = System.currentTimeMillis()/1000 + 600;
}
String userNameStr = mUserName + ";" + getConnectId() + ";" + timestamp;
String userNameStr = mUserName + ";" + getConnectId() + ";" + mExpiredTime;

mConnOptions.setUserName(userNameStr);

Expand Down

0 comments on commit 7975676

Please sign in to comment.