Hi Christian,
I am playing with MQTT over WebSockets on multiple browsers. However the second browser can't connect to the server when the same clientId is used on the client side. It only works if the clientId is generated with unique identifier(random guid on every start/refresh of browser). However in this way the client sessions(_sessions) are increasing on each new connection(they are not cleared on close/refresh). I am testing the MQTTnet.TestApp.AspNetCore2 project with Chrome and IE.
Hi,
yes this is correct. The clientID must be unique and cannot be used by multiple clients.
The sessions are a different topic. In order to support persistent sessions it is required to keep them even if the client is connected. A solution could be adding a options parameter which disables keeping sessions. Then a session can be freed up if the client has been disconnected. In the other case you have to manage the sessions on your own and clean them with custom code.
What do you think about this? And why are you always generating a new client ID?
Best regards
Christian
Hi Christian,
Thank you for your quick response.
Yes, I don't always need to generate a new client ID, instead of that maybe I can get a browser unique ID somehow(using fingerprinting as a technique for instance). But still do you think it will hit a performance issue if there are a lot of browser clients which most of them are already disconnected but all their sessions are always looped in order to publish(enqueue) an application message? I think it will be great if the MqttServerOptions interface has one more option which disables keeping sessions.
What do you think?
Best regards,
Lyubo
I will add this option to the next version.
I also thought about this.
But Id rather like to persist disconnected sessions / subscribtions and load them back on reconnect. that way memory is freed up but you dont loose state....
I can expose a new interface in the options. Something like _ISessionManager_ which implements a interface for loading a session and "closing" a session. The easiest implementation would be the in-memory stuff which is hard coded. But it can be replaced with a different one which persists to the filesystem. Or another one which will always create a new session (persistent sessions disabled).
Any thoughts on that strategy?
sounds good
Good idea
Hi Christian,
Is there any progress on ISessionManager interface? It will be a great implementation.
Best regards,
Lyubo
Doesn't MQTT already have an architecture for this using the CleanSession? I think the standard is:
Client ID: 1 - Connects, receives session
Client ID: 1 - Disconnects (server stores session)
Client ID: 1 - Connects (with clean session flag)
Client ID: 1 - Receives connection resume (but topics are not replayed).
The CleanSession flag should be honored and part of the MqttClient being used.
Any News about this?
The alpha version of 2.8 has some new server options. One of them is disabling the persistent sessions. If the client is in generated there is no need to keep a session. Right?
Hi Christian,
I am playing with MQTT over WebSockets on multiple browsers. However the second browser can't connect to the server when the same clientId is used on the client side. It only works if the clientId is generated with unique identifier(random guid on every start/refresh of browser). However in this way the client sessions(_sessions) are increasing on each new connection(they are not cleared on close/refresh). I am testing the MQTTnet.TestApp.AspNetCore2 project with Chrome and IE.
hi, I am new to mqtt, I study it many weeks.But I just can use it with tcp. I want use it with websocket,But there is not samples.Can you show me some client and server codes with mqtt on websocket?thank you very much!
Here is an example to open websocket https://github.com/chkr1011/MQTTnet/tree/master/Tests/MQTTnet.TestApp.AspNetCore2
This should be in the wiki, too.
Most helpful comment
Here is an example to open websocket https://github.com/chkr1011/MQTTnet/tree/master/Tests/MQTTnet.TestApp.AspNetCore2