Bug 437641 - WebSocket connect fail with array of protocol
Summary: WebSocket connect fail with array of protocol
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Paho (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Andrew Banks CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-18 03:42 EDT by Tang Zi Han CLA
Modified: 2016-02-05 11:15 EST (History)
2 users (show)

See Also:


Attachments
if mqttVersion is set, only apply the matching websockets protocol (1.14 KB, patch)
2014-07-22 11:34 EDT, Karl Palsson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tang Zi Han CLA 2014-06-18 03:42:44 EDT
In Firefox 24+,
Connect fail with 
  new WebSocket(wsurl, ["mqtt","mqttv3.1"]);

The following is ok:
   new WebSocket(wsurl, "mqttv3.1");
Comment 1 Al Stockdill-Mander CLA 2014-07-03 07:08:52 EDT
What server were you connecting to and do you have any trace information?
An array of subprotocols is a valid user (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) Did you also try new WebSocket(wsurl, "mqtt"); ?
Comment 2 Tang Zi Han CLA 2014-07-03 22:30:15 EDT
(In reply to Al Stockdill-Mander from comment #1)
> What server were you connecting to and do you have any trace information?
> An array of subprotocols is a valid user
> (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) Did you also
> try new WebSocket(wsurl, "mqtt"); ?

The server is MQ telemetry 7.5.0.1.

The trace in console:
------------------
"NetworkError: 400 AMQHT0400E: Bad Request. - http://9.119.152.26:1883/mqtt"
mqtt
Firefox can't establish a connection to the server at ws://9.119.152.26:1883/mqtt.

this.socket = new WebSocket(wsurl, ["mqtt","mqttv3.1"]); mqttws31.js (line 968)
"NetworkError: 400 AMQHT0400E: Bad Request. - http://9.119.152.26:1883/mqtt"
mqtt

Connect fail. ErrorCode: 7, ErrorMsg: AMQJS0007E Socket error:undefined. Object { errorCode=7, errorMessage="AMQJS0007E Socket error:undefined.", invocationContext=undefined}     TabConn.js (line 845)
Firefox can't establish a connection to the server at ws://9.119.152.26:1883   /mqtt.
	
this.socket = new WebSocket(wsurl, ["mqtt","mqttv3.1"]);
---------------------------

new WebSocket(wsurl, "mqtt");  is also ok.

It is ok to use MessageSight as server.
Comment 3 Al Stockdill-Mander CLA 2014-07-22 11:00:24 EDT
This appears to be an error in the server, it is legitimate for a client to present an array of sub protocols.
Comment 4 Karl Palsson CLA 2014-07-22 11:33:26 EDT
I would urge you to reconsider.  While it is indeed true that the servers are non-compliant, they are unfortunately out there.  Given that the code already has support for automatic fallback on protocol version, I see no reason to reject any attempt to support servers that only support a single protocol.

Indeed, connecting to a mqtt3.1.1 server and asking for the "mqttv3.1" is already arguably wrong.  Attached is a patch that, if the mqttVersion is set explicitly, only sends the appropriate websockets protocol, instead of the full array each time.

Please consider the patch to public domain
Comment 5 Karl Palsson CLA 2014-07-22 11:34:02 EDT
Created attachment 245273 [details]
if mqttVersion is set, only apply the matching websockets protocol
Comment 6 Al Stockdill-Mander CLA 2014-07-22 12:05:17 EDT
Actually there is a good option here for a fallback similar to the way we handle protocol levels
Comment 7 Al Stockdill-Mander CLA 2014-07-23 10:00:37 EDT
Implemented a simple switch so that mqttv3.1 is transmitted when V3 and mqtt is transmitted when V4.