Connect failed: AMQJS0007E Socket error:undefined

I tried MQTT Websocket Client to connect to a mosquitto broker/server.
I got the error message:
Connect failed: AMQJS0007E Socket error:undefined.

I have the MQTTX client works with the mosquitto broker/server.
When I compared the GET html packets, I saw the following differences:
From HiveMQ:
Sec-Websocket-Protocol mqttv3.1\r\n
From MQTTX
Sec-Websocket-Protocol mqtt\r\n

How to fix the issue?
How can I configure the HiveMQ to send Sec-Websocket-Protocol mqtt\r\n

Hi @dennisnguy ,

Can you connect using MQTT CLI client? The command should look like mqtt publish --topic Test --message Hello --hostname <my-host> --port <my-port> -ws --debug, where the -ws indicates Use WebSocket transport protocol (default: false) and --debug to provide verbose output.

I hope this helps,
Dasha from HiveMQ team

Hi @Daria_H

The MQTT CLI client works. It sends: sec-websocket-protocol: mqtt\r\n
(it does not send: sec-websocket-protocol: mqttv3.1\r\n)

I’m using this command from a windows 10 os:
.\mqtt-cli.exe pub --topic “spBv1.0/Sparkplug B Devices/NCMD/C Edge Node 1” --message “Hello” --host “10.1.1.223” --port 61614 -ws --debug

D:\work\tools\mqtt_cli_hivemq>.\mqtt-cli.exe pub --topic “spBv1.0/Sparkplug B Devices/NCMD/C Edge Node 1” --message “Hello” --host “10.1.1.223” --port 61614 -ws --debug
Client ‘UNKNOWN@10.1.1.223’ sending CONNECT MqttConnect{keepAlive=60, cleanStart=true, sessionExpiryInterval=0}
Client ‘UNKNOWN@10.1.1.223’ received CONNACK MqttConnAck{reasonCode=SUCCESS, sessionPresent=false, assignedClientIdentifier=auto-551A30BA-F241-90B6-8B86-83333C476ED6, restrictions=MqttConnAckRestrictions{receiveMaximum=65535, maximumPacketSize=268435460, topicAliasMaximum=10, maximumQos=EXACTLY_ONCE, retainAvailable=true, wildcardSubscriptionAvailable=true, sharedSubscriptionAvailable=true, subscriptionIdentifiersAvailable=true}}
Client ‘auto-551A30BA-F241-90B6-8B86-83333C476ED6@10.1.1.223’ sending PUBLISH (‘Hello’) MqttPublish{topic=spBv1.0/Sparkplug B Devices/NCMD/C Edge Node 1, payload=5byte, qos=AT_MOST_ONCE, retain=false}
Client ‘auto-551A30BA-F241-90B6-8B86-83333C476ED6@10.1.1.223’ received PUBLISH acknowledgement MqttPublishResult{publish=MqttPublish{topic=spBv1.0/Sparkplug B Devices/NCMD/C Edge Node 1, payload=5byte, qos=AT_MOST_ONCE, retain=false}}

Wireshark info:
Hypertext Transfer Protocol
GET /mqtt HTTP/1.1\r\n
[Expert Info (Chat/Sequence): GET /mqtt HTTP/1.1\r\n]
Request Method: GET
Request URI: /mqtt
Request Version: HTTP/1.1
host: 10.1.1.223:61614\r\n
upgrade: websocket\r\n
connection: upgrade\r\n
sec-websocket-key: rEDydrkMPRMBTGyP02ol3Q==\r\n
origin: http://10.1.1.223:61614\r\n
sec-websocket-protocol: mqtt\r\n
sec-websocket-version: 13\r\n
\r\n
[Full request URI: http://10.1.1.223:61614/mqtt]
[HTTP request 1/1]
[Response in frame: 8]

Thanks

@dennisnguy ,

Great that MQTT CLI works! I hope you can use it as a workaround now.

The error that you indicated with WebSocket client I can only reproduce when using a wrong port number (normal MQTT-TCP listener instead of WebSocket one). Hence the question:

  • Does your broker have many listeners or only WebSocket on the port 61614?
  • Are you using the same port (61614) with WebSocket client as with MQTT CLI, and in case of the WebSocket Client it fails and in with MQTT CLI it succeeds?

Please feel free to share your WireShark capture port 61614 with WebSocket client and point out where the text “Sec-Websocket-Protocol mqttv3.1\r\n” comes from.

Kind regards,
Dasha

Hi Dasha,

  • My mosquitto broker has only one mqtt websockets port number = 61614
  • I have used the same port number when I tested mqtt websockets clients.

Below is the mqtt websockets captured from Wireshark using the web websocket-client
Frame 314874: 581 bytes on wire (4648 bits), 581 bytes captured (4648 bits) on interface \Device\NPF_{B77E048F-733F-45F0-8002-5EF4EF84E778}, id 0
Ethernet II, Src: MegaWell_32:6d:05 (10:5b:ad:32:6d:05), Dst: ee:8f:80:24:38:c3 (ee:8f:80:24:38:c3)
Internet Protocol Version 4, Src: 10.1.1.253, Dst: 10.1.1.223
Transmission Control Protocol, Src Port: 57979, Dst Port: 61614, Seq: 1, Ack: 1, Len: 527
Hypertext Transfer Protocol
GET /mqtt HTTP/1.1\r\n
[Expert Info (Chat/Sequence): GET /mqtt HTTP/1.1\r\n]
Request Method: GET
Request URI: /mqtt
Request Version: HTTP/1.1
Host: 10.1.1.223:61614\r\n
Connection: Upgrade\r\n
Pragma: no-cache\r\n
Cache-Control: no-cache\r\n
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36\r\n
Upgrade: websocket\r\n
Origin: http://www.hivemq.com\r\n
Sec-WebSocket-Version: 13\r\n
Accept-Encoding: gzip, deflate\r\n
Accept-Language: en-US,en;q=0.9\r\n
Sec-WebSocket-Key: Mlv7c4rOVfriQYFdRZ7Dgw==\r\n
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n
Sec-WebSocket-Protocol: mqttv3.1\r\n
\r\n
[Full request URI: http://10.1.1.223:61614/mqtt]
[HTTP request 1/1]

Wireshark data packet, from: .\mqtt-cli.exe pub --topic “spBv1.0/Sparkplug B Devices/NCMD/C Edge Node 1” --message “Hello” --host “10.1.1.223” --port 61614 -ws --debug
(This works). The one from Websockets Client Showcase Does not work.

Frame 4: 276 bytes on wire (2208 bits), 276 bytes captured (2208 bits) on interface \Device\NPF_{B77E048F-733F-45F0-8002-5EF4EF84E778}, id 0
    Interface id: 0 (\Device\NPF_{B77E048F-733F-45F0-8002-5EF4EF84E778})
    Encapsulation type: Ethernet (1)
    Arrival Time: Sep 27, 2022 12:21:54.394893000 Pacific Daylight Time
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1664306514.394893000 seconds
    [Time delta from previous captured frame: 0.026524000 seconds]
    [Time delta from previous displayed frame: 0.026524000 seconds]
    [Time since reference or first frame: 0.029651000 seconds]
    Frame Number: 4
    Frame Length: 276 bytes (2208 bits)
    Capture Length: 276 bytes (2208 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ip:tcp:http]
    [Coloring Rule Name: HTTP]
    [Coloring Rule String: http || tcp.port == 80 || http2]
Ethernet II, Src: MegaWell_32:6d:05 (10:5b:ad:32:6d:05), Dst: ee:8f:80:24:38:c3 (ee:8f:80:24:38:c3)
Internet Protocol Version 4, Src: 10.1.1.253, Dst: 10.1.1.223
Transmission Control Protocol, Src Port: 63855, Dst Port: 61614, Seq: 1, Ack: 1, Len: 222
Hypertext Transfer Protocol
    GET /mqtt HTTP/1.1\r\n
        [Expert Info (Chat/Sequence): GET /mqtt HTTP/1.1\r\n]
        Request Method: GET
        Request URI: /mqtt
        Request Version: HTTP/1.1
    host: 10.1.1.223:61614\r\n
    upgrade: websocket\r\n
    connection: upgrade\r\n
    sec-websocket-key: EQisDH73AfZ7XdDevbUgyg==\r\n
    origin: http://10.1.1.223:61614\r\n
    sec-websocket-protocol: mqtt\r\n
    sec-websocket-version: 13\r\n
    \r\n
    [Full request URI: http://10.1.1.223:61614/mqtt]
    [HTTP request 1/1]
    [Response in frame: 6]