I have a few questions about WILL message publishing. There are several scenarios in which I am unsure if the WILL should be published. I understand that if the client sends a DISCONNECT then a broker should not publish the WILL. I am unsure about the scenarios below.
1) A client is connecting with the ID of an existing connected client. It is my understanding that the currently connected client connection should be closed and the new client should be connected. Should the will of the closed/previous client be published?
2) A client loses connection because of a network failure but immediately reconnects. Should the WILL be published or should the broker wait for some period (e.g. client timeout) before publishing the WILL. This seems unnecessary if the client immediately reconnects.
3) A client sends a DISCONNECT message and immediately terminates the socket connection. The broker, depending on the processing model and message queue, could (and is very likely with async IO) recognize the connection termination before processing the DISCONNECT message. The broker now has to wait, set a timer, or look ahead in the mesage queue to see if there is DISCONNECT for the client. A wait time, possibly the broker keep alive timer, could resolve this issue as well as #2.
4) In the event that the broker must shut down. Should WILL messages be published for connected clients? If so, how, since the clients must all be disconnected before the shutdown? Do you publish the WILLs before disconnecting any clients so they all receive each others WILLS?
I am in the process of finishing a full featured interface driven extendable C# MQTT broker and client (including Netduino) which I hope to make available to the community. Thanks again for the help.
Thanks,
-Michael Combs