OnMQTTBeforeConnect event, there is a parameter called aCleanSession. If the value of this parameter is True, means that client want start a new session, so if server has any session stored, it must discard it. So, when OnMQTTConnect event is fired, aSession parameter will be false. If the value of this parameter is False and there is a session associated to this client identifier, the server must resume communications with the client on state with the existing session.
So, if client has an unexpected disconnection, and you want to recover the session where was disconnected, in OnMQTTBeforeConnect set aCleanSession = True and aClientIdentifier = Client ID of Session.
Once successful connection, check OnMQTTConnect event, the value of Session parameter.
Session = true, means session has been resumed.
Session = false, means it's a new session.
void OnMQTTBeforeConnect(TsgcWSConnection Connection, ref bool aCleanSession,
ref string aClientIdentifier)
{
aCleanSession = false;
aClientIdentifier = "previous client id";
}
void OnMQTTConnect(TsgcWSConnection Connection, bool Session, int ReasonCode,
string ReasonName, TsgcWSMQTTCONNACKProperties ConnectProperties);
{
if (Session == true)
{
Console.WriteLine("Session resumed");
}
else
{
Console.WriteLine("New Session");
}
}