永发信息网

如何理解mqtt的mqttcallback类

答案:2  悬赏:70  手机版
解决时间 2021-01-28 12:42
  • 提问者网友:浪荡绅士
  • 2021-01-28 03:09
如何理解mqtt的mqttcallback类
最佳答案
  • 五星知识达人网友:酒醒三更
  • 2021-01-28 03:50
MQTT连接建立的代码(SSL方式)

[java] view plain copy
public static void connect(Driver driver) {
ServerConfig serverConfig = UserModule.Instance.getServerConfig();
MqttConnectOptions conOpt = new MqttConnectOptions();
try {
SSLContext sslContext;
KeyStore ts = KeyStore.getInstance("BKS");
ts.load(context.getResources().openRawResource(R.raw.test_cert),
"123456".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(ts);
TrustManager[] tm = tmf.getTrustManagers();
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tm, null);

SocketFactory factory = sslContext.getSocketFactory();
conOpt.setSocketFactory(factory);
} catch (Exception e) {
e.printStackTrace();
}

[java] view plain copy
//paho库得
Iterator> it = Connections
.getInstance(context).getConnections().entrySet().iterator();
while (it.hasNext()) {
MqttClientAndroidService detectClient = it.next().getValue()
.getClient();
try {
detectClient.disconnect();
} catch (MqttException e) {
e.printStackTrace();
}
it.remove();
}
全部回答
  • 1楼网友:duile
  • 2021-01-28 04:55
不明白啊 = =!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯