Closed jetompki closed 5 years ago
Ok, it looks as though this line in the code is causing your problems
'final List
We only do this on web socket connections. from the Dart API docs
'The protocols argument is specifying the subprotocols the client is willing to speak.'
This part of websocket spec refers, this document section 5.2.1 point 6 states
'Optionally, a "Sec-WebSocket-Protocol" header, with a list of values indicating which protocols the client would like to speak, ordered by preference.'
This does say list of values, but I can't find any info on what this list actually is, i.e. what the separator is.
Your the first to report this, the client is being used in a number of websocket and secure websocket projects with different MQTT brokers, e.g Mosquito, Paho, cloud IOT solutions from IBM, Google, Amazon, Azure etc so I'm loath to change this, however I can add a flag to disable the list setting and just set it to 'mqtt' or maybe allow the user to specify the subprotocol maybe if you think this would help you.
I've tested it by using the project locally and altering the
final List protocols = ['mqtt', 'mqttv3.1', 'mqttv3.11'];
to
final List protocols = ['mqtt'];
And I can successfully connect to my MQTTNet broker.
I believe that the latter you suggested -- allowing the user to specify the subprotocol(s) would be more flexible. You could continue to keep the default implementation (which I assume is 'final List protocols = ['mqtt', 'mqttv3.1', 'mqttv3.11'];') then allow an override with a custom list of protocols which you can specify when building the MQTTClient. Something like:
MQTTClient client = new MQTTClient(...);
List protocols = ['mqtt'];
client.useWebSocketSubProtocols(protocols);
I appreciate the help, and please update the project at your discretion.
Setter websocketProtocols added on to the client to set default protocols, add your own or swith this off entirely, see the API docs for more details, client re-published at 5.3.0, please retest.
I have an issue, dsoe not say i have to specify protocol, but wanted to give it a try, i get the following error;
Error: The method 'websocketProtocols' isn't defined for the class 'mqtt_client::MqttClient'.
Try correcting the name to the name of an existing method, or defining a method named 'websocketProtocols'.
client.websocketProtocols(protocols);
^^^^^^^^^^^^^^^^^^
Check you are using at least version 5.3.0, note the method isn't static, you need to call it on an instantiated client,
final MqttClient client = MqttClient('test.mosquitto.org', ''); client.websocketProtocols(MqttWsConnection.protocolsSingleDefault)
for example
Hey, i still have the same issue, just created new dart project, from the exmples dir,
final MqttClient client = MqttClient('test.mosquitto.org', '');
client.websocketProtocols(MqttWsConnection.protocolsSingleDefault), i notice you did not have ;
why is that?
v. 5.4.0
note: am using dart 2.1.0
can i ask for websockets example in the examples dir?
Sorry my bad, the websocketProtocols API is a setter, not a method, please do this client.websocketProtocols = MqttWsConnection.protocolsSingleDefault; etc.
Retested and is working as expected, thanks.
I have a MQTTNet server on my local host at http://localhost:65061 and a separate Android Device (not emulator) connected via USB.
Using a sample MQTTNet client console app in C#, I can successfully connect to it using the following:
I'm using the sample Flutter mqtt_client from
I attempt to connect like this:
I can see the get request reaching my MQTTNet server, however it errors out: Notice System.ArgumentException: The WebSocket protocol 'mqtt, mqttv3.1, mqttv3.11' is invalid because it contains the invalid character ','. may be relevant.
I then see in my flutter app an error which states connection not upgraded to websocket (presumably because of the error on the server side?):
Any ideas?
edit Also note that I can seemingly do all the requirements I can think of from my android device.
If I use chrome browser on my Android device and enter localhost:65061 I access the home page of my server. If I implement an api on my server, I can retrieve the values that the api provides via a HttpGet using the flutter http package.
It just seems that this MqttClient doesn't work.