How to connect to websocket for the following setting?
TomWangTW opened this issue · 1 comments
Checklist
- [v] I've searched the project's
issues
. - [v] I've searched the project's
discussions
.
❓ Question
How to connect to websocket for the following setting?
address: wss://xxx.com:8084
so i seperated the address to
- host: xxx.com
- port: 8084
I used below config but it always get error like this:
cause: io.netty.handler.codec.http.websocketx.WebSocketHandshakeException: Invalid handshake response getStatus: 404 Not Found
but this address is work well with eclipse mqtt client
mqttClient = Mqtt3Client
.builder()
.serverHost(host) //xxx.com
.serverPort(port) //8084
.webSocketConfig()
.applyWebSocketConfig()
.identifier(mqttInfo.mqttId)
.simpleAuth()
.username(mqttInfo.mqttUsername)
.password(mqttInfo.mqttPassword.toByteArray())
.applySimpleAuth()
.buildAsync()
@TomWangTW wss
is secure web sockets and based on the configuration you posted the endpoint the client will try is not secure (ie. ws://xxx.com:8084). You should just have to add an ssl config to get around this error, like this:
mClient = Mqtt3Client.builder()
.serverHost(host) //xxx.com
.serverPort(port) //8084
.sslWithDefaultConfig()
.webSocketConfig()
.applyWebSocketConfig()
.identifier(mqttInfo.mqttId)
.simpleAuth()
.username(mqttInfo.mqttUsername)
.password(mqttInfo.mqttPassword.toByteArray())
.applySimpleAuth()
.buildAsync();
I would strongly suggest adding disconnect/connect listeners as well to get more information about the connection, and if possible consider using MQTT5 since it is more verbose with errors. Hope that helps!