MQTT.js
MQTT.js copied to clipboard
ws error event can't listener
I used the wrong host for the ws connection, and found that I could not monitor the "error" event, which made it impossible to determine whether the connection was successful.
However, I printed the client's information and found that socket onxx events are all null.
I added this function, and his message was forwarded before it was accepted successfully
this.client.stream.socket.onerror = function (event) { console.error("WebSocket error observed:", event); emiterror(event) }; const emiterror = (e: any) => { this.emit('error', e) }
Without the above function, I cannot receive error messages.
client.on('error',err=>{})
The built-in on event cannot work.
I think my operation is not the final solution. How do I get the error message?