Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MqttClient re-usable so you can connect and disconnect at will #7

Open
markallanson opened this issue Oct 20, 2013 · 2 comments
Open
Milestone

Comments

@markallanson
Copy link
Owner

Currently an MqttClient is single use - meaning you need to dispose and create a new one to reconnect. It would be useful to be able to pull the connection up and down and have subscriptions re-sync without having to do these cleanups.

@nidayand
Copy link

How can I catch the fact that I have to re-connect. I'm currently wrapping nmqtt in a try-catch block but I cannot catch the fact that nmqtt is disconnected in order to do a dispose and reconnect (I've tested by shutting down the MQTT-broker)

{UnhandledExceptionController_Framework} -- -- 2013-11-27 08:55:30 -- Exception:
System.ObjectDisposedException
Level 1) Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
StackTrace for Level 1:
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at Nmqtt.MqttConnection.Send(Byte[] message)
at Nmqtt.MqttConnection.Send(Stream message)
at Nmqtt.MqttConnectionHandler.SendMessage(MqttMessage message)
at Nmqtt.MqttConnectionKeepAlive.PingRequired(Object state)
at System.Threading._TimerCallback.TimerCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._TimerCallback.PerformTimerCallback(Object state)

Appreciate the help :-)

@markallanson
Copy link
Owner Author

Unfortunately there is no nice way of doing this at the moment.

The connection state is exposed on the MqttClient class and you can monitor that, but there is no pro-active notification. It’s a big hole I need to fill!

On Wednesday, 27 November 2013 at 08:26, Peter wrote:

How can I catch the fact that I have to re-connect. I'm currently wrapping nmqtt in a try-catch block but I cannot catch the fact that nmqtt is disconnected in order to do a dispose and reconnect (I've tested by shutting down the MQTT-broker)
{UnhandledExceptionController_Framework} -- -- 2013-11-27 08:55:30 -- Exception:
System.ObjectDisposedException
Level 1) Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
StackTrace for Level 1:
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at Nmqtt.MqttConnection.Send(Byte[] message)
at Nmqtt.MqttConnection.Send(Stream message)
at Nmqtt.MqttConnectionHandler.SendMessage(MqttMessage message)
at Nmqtt.MqttConnectionKeepAlive.PingRequired(Object state)
at System.Threading.TimerCallback.TimerCallbackContext(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._TimerCallback.PerformTimerCallback(Object state)
Appreciate the help :-)


Reply to this email directly or view it on GitHub (#7 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants