Java 安卓MQTT-Paho不';不支持wss://
我正在使用泛美卫生组织的Android客户端。 这可能是Android上MQTT的go-to库,但它不支持安全的MQTT WebSocket(wss://),这给了我服务器uri的IllegaArgument异常 我一直在寻找一种连接到我的MQTT websocket的解决方案,它有一个wss://路径方案,到目前为止,只有一个库: 这也不行!我收到Jetty SSL异常 如果您有一个以前使用过的实现,请与我分享,这花费了我很多时间,我仍然不知道,谢谢强>Java 安卓MQTT-Paho不';不支持wss://,java,android,websocket,mqtt,paho,Java,Android,Websocket,Mqtt,Paho,我正在使用泛美卫生组织的Android客户端。 这可能是Android上MQTT的go-to库,但它不支持安全的MQTT WebSocket(wss://),这给了我服务器uri的IllegaArgument异常 我一直在寻找一种连接到我的MQTT websocket的解决方案,它有一个wss://路径方案,到目前为止,只有一个库: 这也不行!我收到Jetty SSL异常 如果您有一个以前使用过的实现,请与我分享,这花费了我很多时间,我仍然不知道,谢谢 对于这两个库,我都尝试使用它们在文档中
对于这两个库,我都尝试使用它们在文档中提供的示例代码。我认为Paho Android客户端不支持websocket ssl,但您可以使用MqttAsyncClient代替MqttAndroidClient,如下所示: 这些库是相同的:
dependencies {
...
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.0'
...
}
使用MqttAsyncClient代替MqttAndroidClient,如下所示:
private MqttAsyncClient mMqttAndroidClient;
try {
mMqttAndroidClient = new MqttAsyncClient("wss://...", MqttClient.generateClientId(), new MemoryPersistence());
} catch (MqttException e) {
e.printStackTrace();
}
我认为Paho Android客户端不支持websocket ssl,但您可以使用MqttAsyncClient代替MqttAndroidClient,如下所示: 这些库是相同的:
dependencies {
...
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.0'
...
}
使用MqttAsyncClient代替MqttAndroidClient,如下所示:
private MqttAsyncClient mMqttAndroidClient;
try {
mMqttAndroidClient = new MqttAsyncClient("wss://...", MqttClient.generateClientId(), new MemoryPersistence());
} catch (MqttException e) {
e.printStackTrace();
}
我使用“WSS://”没有任何问题。使用“WSS”架构和端口443创建MqttAndroidClient对象
mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setKeepAliveInterval(MqttConfig.KEEPALIVE);
mqttConnectOptions.setUserName("username");
mqttConnectOptions.setPassword("pass");
mqttConnectOptions.setCleanSession(false);
mqttConnectOptions.setAutomaticReconnect(true);
mqttConnectOptions.setMaxInflight(1024);
..
uri="wss://broker.hivemq.com:443"
MqttAndroidClient client = new MqttAndroidClient(context, uri, clientId,persistence);
..
getClient().connect(mqttConnectOptions,applicationContext,mqttActionListener;
我使用“WSS://”没有任何问题。使用“WSS”架构和端口443创建MqttAndroidClient对象
mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setKeepAliveInterval(MqttConfig.KEEPALIVE);
mqttConnectOptions.setUserName("username");
mqttConnectOptions.setPassword("pass");
mqttConnectOptions.setCleanSession(false);
mqttConnectOptions.setAutomaticReconnect(true);
mqttConnectOptions.setMaxInflight(1024);
..
uri="wss://broker.hivemq.com:443"
MqttAndroidClient client = new MqttAndroidClient(context, uri, clientId,persistence);
..
getClient().connect(mqttConnectOptions,applicationContext,mqttActionListener;
没有真正的问题here@hardillb问题是如何连接到android上的MQTT websocket,因为当前的解决方案不起作用?没有真正的问题here@hardillb问题是如何连接到android上的MQTT websocket,因为当前的解决方案不起作用?