Comments (25)
Yes, that's the problem. websockets
sees that mqtt3.1
isn't in the list of supported protocols, so it sends a response without a subprotocol. The browser doesn't like it and closes the connection.
from hbmqtt.
Strange here : your test page works fine with safari or firefox : mqtt.js connects to the broker and push a message.
When running with chrome, I get the following error on the broker side : Can't read first packet an CONNECT: No more data.
There may be an issue with mqtt.js and chrome.
from hbmqtt.
sorry.
Requests header are :
Accept-Encoding:gzip, deflate, sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:Upgrade
Host:127.0.0.1:8080
Origin:file://
Pragma:no-cache
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
Sec-WebSocket-Key:NPmcezVmRV+sFU0Id+vgiA==
Sec-WebSocket-Protocol:mqttv3.1
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
response headers are :
Connection:Upgrade
Sec-WebSocket-Accept:v5mPtGVrLeq0QvZB0lCUmmuvDaU=
Server:Python/3.5 websockets/3.1
Upgrade:WebSocket
from hbmqtt.
ok, so that's a problem with the client which should send mqtt
as subprotocol (according to MQTT specification)
from hbmqtt.
Hi,
hbmqtt only supports MQTT 3.1.1. The error you mention reminds me what happen when you connect with MQTT protocol 3.1. I agree this is not clear...
To check, could you run hbmqtt broker with the -d option (debug mode), then paste the complete trace ?
from hbmqtt.
Hi,
According to mqtt.js, the protocol used is MQTT 3.1.1 ( https://www.npmjs.com/package/mqtt ).
However, the hbmqtt receives a MQTT 3.1.0-1 client:
[2016-05-17 11:01:34,646] :: INFO :: hbmqtt.broker :: Listener 'ws-mqtt': 1/10 connections acquired
[2016-05-17 11:01:34,646] :: INFO :: hbmqtt.broker :: Connection from 127.0.0.1:51671 on listener 'ws-mqtt'
[2016-05-17 11:01:34,647] :: INFO :: websockets.protocol :: Failing the WebSocket connection: 1006
[2016-05-17 11:01:34,647] :: WARNING :: hbmqtt.broker :: [MQTT-3.1.0-1](client @=127.0.0.1:51671): Can't read first packet an CONNECT: No more data
May the websockets be only compatible with 3.1.0 ?
Thanks for your answer.
EDIT
I have the following configuration:
`config = {
'listeners': {
'default': {
'type': 'tcp',
'bind': '0.0.0.0:1883',
}
,
'ws-mqtt': {
'bind': '127.0.0.1:8888',
'type': 'ws',
'max_connections': 10,
},
},
'sys_interval': 10,
'auth': {
'allow-anonymous': True,
'plugins': [
'auth_file', 'auth_anonymous'
]
}
}`
The previous described results are using the second listener. I tried to use the first one now, and it receives the connection message, and a few minutes later, a connection time out occurs in the browser and the broker prints:
[2016-05-17 11:48:16,541] :: WARNING :: hbmqtt.broker :: [MQTT-3.1.0-1](client @=127.0.0.1:35430): Can't read first packet an CONNECT: No more data
from hbmqtt.
According to a issue ( https://github.com/beerfactory/hbmqtt/issues/20 ), with version 0.6.2 this library must work properly with the HiveMQ Demo ( http://www.hivemq.com/demos/websocket-client/ ). However, I try to insert my local host address in this demo, and I receive the same error in the browser, as well as the broker. I have 0.6.3 version.
EDIT:
I have tried versions 0.6.2, as well as 0.7.1 and the same results happen.
from hbmqtt.
Hi,
Can you :
- test with the latest hbmqtt version (0.7.1)
- run your hbmqtt broker with the -d option. Then paste here the whole trace, it should show every packet content.
from hbmqtt.
Using version 0.7.1
[vsantos@vs-pc dioti_webApp]$ hbmqtt -d
[2016-05-17 15:00:29,058] :: DEBUG - Using default configuration
[2016-05-17 15:00:29,059] :: DEBUG - Using selector: EpollSelector
[2016-05-17 15:00:29,059] :: DEBUG - Loading plugins for namespace hbmqtt.broker.plugins
[2016-05-17 15:00:29,089] :: DEBUG - Loading plugin broker_sys = hbmqtt.plugins.sys.broker:BrokerSysPlugin
[2016-05-17 15:00:29,097] :: DEBUG - Initializing plugin broker_sys = hbmqtt.plugins.sys.broker:BrokerSysPlugin
[2016-05-17 15:00:29,097] :: DEBUG - Plugin broker_sys ready
[2016-05-17 15:00:29,097] :: DEBUG - Loading plugin packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin
[2016-05-17 15:00:29,098] :: DEBUG - Initializing plugin packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin
[2016-05-17 15:00:29,098] :: DEBUG - Plugin packet_logger_plugin ready
[2016-05-17 15:00:29,098] :: DEBUG - Loading plugin auth_file = hbmqtt.plugins.authentication:FileAuthPlugin
[2016-05-17 15:00:29,110] :: DEBUG - loaded lazy attr 'SafeConfigParser': <class 'configparser.ConfigParser'>
[2016-05-17 15:00:29,110] :: DEBUG - loaded lazy attr 'NativeStringIO': <class '_io.StringIO'>
[2016-05-17 15:00:29,110] :: DEBUG - loaded lazy attr 'BytesIO': <class '_io.BytesIO'>
[2016-05-17 15:00:29,111] :: DEBUG - Initializing plugin auth_file = hbmqtt.plugins.authentication:FileAuthPlugin
[2016-05-17 15:00:29,111] :: DEBUG - Configuration parameter 'password_file' not found
[2016-05-17 15:00:29,111] :: DEBUG - Plugin auth_file ready
[2016-05-17 15:00:29,111] :: DEBUG - Loading plugin auth_anonymous = hbmqtt.plugins.authentication:AnonymousAuthPlugin
[2016-05-17 15:00:29,111] :: DEBUG - Initializing plugin auth_anonymous = hbmqtt.plugins.authentication:AnonymousAuthPlugin
[2016-05-17 15:00:29,112] :: DEBUG - Plugin auth_anonymous ready
[2016-05-17 15:00:29,121] :: DEBUG - Broker starting
[2016-05-17 15:00:29,123] :: INFO - Listener 'default' bind to 0.0.0.0:1883 (max_connections=-1)
[2016-05-17 15:00:29,123] :: DEBUG - Broker started
[2016-05-17 15:00:29,123] :: DEBUG - Retaining message on topic $SYS/broker/version
[2016-05-17 15:00:29,123] :: DEBUG - Setup $SYS broadcasting every 20 secondes
[2016-05-17 15:00:33,525] :: INFO - Listener 'default': 1 connections acquired
[2016-05-17 15:00:33,525] :: INFO - Connection from 127.0.0.1:38451 on listener 'default'
[2016-05-17 15:00:37,754] :: WARNING - [MQTT-3.1.0-1](client @=127.0.0.1:38451): Can't read first packet an CONNECT: No more data
[2016-05-17 15:00:37,754] :: DEBUG - Connection closed
[2016-05-17 15:00:42,258] :: INFO - Listener 'default': 2 connections acquired
[2016-05-17 15:00:42,258] :: INFO - Connection from 127.0.0.1:38469 on listener 'default'
Afterwards, I stop the client and:
[2016-05-17 15:01:20,365] :: WARNING - [MQTT-3.1.0-1](client @=127.0.0.1:38469): Can't read first packet an CONNECT: No more data
[2016-05-17 15:01:20,365] :: DEBUG - Connection closed
from hbmqtt.
could you send the test page (with mqtt.js) you're using ?
from hbmqtt.
Sure, here it is.
https://www.dropbox.com/sh/ww7tx3wvo1v7w5q/AABC9jsne_VT87t50Ukda7hWa?dl=0
The javascript file was generated using browserify as it is explained in mqtt.js documentation.
from hbmqtt.
Hi,
I guess there's a problem with your configuration. The html sample you sent me connect to 'ws://127.0.0.1:1883' which means connect on TCP port 1883 using websocket protocol. According to your previous comment, port 1883 is bind with rough TCP protocol. The broker can't accept it.
If you change your connection string to ws://127.0.0.1:8888 it should work.
For me the following example works fine :
var client = mqtt.connect('ws://127.0.0.1:8080'); client.on('connect', function () { client.subscribe('presence'); client.publish('presence', 'Hello mqtt'); client.end(); });
from hbmqtt.
Hi again,
Thanks for your time. I change the port just for testing purposes, I had previously tried to use your port 8888, but it didn't work either.
Can you check my new files, as well as the python broker configuration in order to verify my configurations?
https://www.dropbox.com/sh/ww7tx3wvo1v7w5q/AABC9jsne_VT87t50Ukda7hWa?dl=0
from hbmqtt.
That's true, I was using chrome. I switched to firefox and it works properly. Therefore, it is a problem from mqtt.js, I will create an issue for it.
Thanks!
from hbmqtt.
reopened following last message from mqtt.js#408 : mqtt.js seems to work fine with chrome and mosquitto through websocket.
from hbmqtt.
@aaugustin, could you help with this problem ?
to sum up : hbmqtt is a MQTT broker (messaging server) which uses websockets for implementing the server side. A problem is reported by @vasco-santos reported when using MQTT.js client from chrome browser : websocket connection to the broker doesn't work, the connection is closed. Same code runs fine from with firefox or safari (connection is established and data flows). So we first thought of a chrome related problem, but guys from MQTT.js say their code works fine with chrome and some other MQTT broker implementation. So back to hbmqtt problem...
My analysis is that the error comes from this line in hbmqtt which receives incoming data. For some unknown reason this line throws a ConnectionClosed
exception when the connection comes from MQTT.js/chrome. If the connection comes from MQTT.js/firefow for example, I can read data.
I guess there may be an problem in websockets with chrome websocket implementation. Are you aware of that ?
There's a wireshark capture available here in case : mqtt.js#408
from hbmqtt.
The error message suggests that Chrome doesn't receive a confirmation of the subprotocol it selects. websockets contains an API to enable a subprotocol but it is a fairly recent feature and hasn't received a lot of testing yet. Can you check whether the response HTTP headers confirm the subprotocol requested in the request?
from hbmqtt.
Here is a dump of HTTP header as shown in Chrome inspector:
Request URL:ws://127.0.0.1:8080/
Request Method:GET
Status Code:101 Switching Protocols
Response Headers
view source
Connection:Upgrade
Sec-WebSocket-Accept:v5mPtGVrLeq0QvZB0lCUmmuvDaU=
Server:Python/3.5 websockets/3.1
Upgrade:WebSocket
Request Headers
view source
Accept-Encoding:gzip, deflate, sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:Upgrade
Host:127.0.0.1:8080
Origin:file://
Pragma:no-cache
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
Sec-WebSocket-Key:NPmcezVmRV+sFU0Id+vgiA==
Sec-WebSocket-Protocol:mqttv3.1
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Name
from hbmqtt.
I'm not sure which of these are request or response headers :-/
Origin:file://
is unlikely to work well. Perhaps that's why the connection gets closed prematurely.
I only see one Sec-WebSocket-Protocol:mqttv3.1
while it should be in the request and the response.
from hbmqtt.
When using a local web server instead of static file I have Origin:http://localhost:8000
but the connection problem remains.
from hbmqtt.
So you're clearly missing a Sec-WebSocket-Protocol
header in the response. I'm not sure how you're using websockets in this project, can you show me where you enable the subprotocol?
from hbmqtt.
could it be subprotocol mismatch ?
According to MQTT specifications, subprotocol must be set to mqtt
. Therefore my server code adds subprotocols=['mqtt']
as additional argument to websockets.serve()
. I see that in the request, the protocol is mqttv3.1
. Could it be the problem ?
=> subprotocol is enable here in my code.
from hbmqtt.
Just a clarification 'mqttv3.1'
is the informal old subprotocol (for MQTT v3.1), which all brokers still recognize. MQTT.js will send the correct subprotocol, but for compatibility reason I would suggest to support both here (maybe with a warning).
from hbmqtt.
hbmqtt only supports MQTT 3.1.1 and mqtt
is the only subprotocol required by this version. According to the spec, using another protocol is not allowed (see [MQTT-6.0.0-3] and [MQTT-6.0.0-4]). Besides, supporting and old subprotocol wouldn't help clients in conforming to these specifications.
from hbmqtt.
I tend to disagree, as these things are really hard to debug, and there are plenty of clients out there that are sending out 3.1 data.
from hbmqtt.
Related Issues (20)
- Release 0.9.7 HOT 3
- Broker: client reconnect keep-alive grows infinitely and client take over not implemented
- Python 3.9 Breaks HBMQTT: 'Lock' object is not iterable HOT 1
- Call publish from a different thread HOT 3
- Docs do not mention how to reconnect forever
- travis ci is going to retire HOT 1
- Mosquitto CA test file expired? HOT 2
- Tests fail on master after latest merge HOT 3
- The future of hbmqtt? Is it still maintained or EOL? HOT 9
- Replay and retained message logic need work (biggest issue: inactive client sessions grow RAM forever)
- Install with Poetry fails HOT 4
- Issue: ModuleNotFoundError: No module named 'websockets.protocol' HOT 8
- broker question
- how to write a broker plugin? Or is that even what I want to do?
- broker内存越来越大。
- Python 3.9 Breaks HBMQTT: 'Lock' object is not iterable HOT 4
- BrokerException inherits BaseException and is not caught by except Exception: HOT 1
- python 3.10.4 executes asyncio error:the *loop* parameter was removed from Event() since it is no longer necessary
- Error with recent websockets package HOT 1
- sha-512
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hbmqtt.