I have been reading this tutorial to learn the basics of Paho android Service API
, and some where in the text i read as for client.connect(context, callback
which has two methods onSuccess()
and onFailure()
As mentioned, a synchronous client is being used in this example (MqttClient as opposed to MqttAsyncClient). This means that requests, like connect, will block and return or throw an exception. There is no polling or read method to get messages from the server, messages from the server can arrive at any time. The library provides a callback mechanism to handle this behavior, methods in an MqttCallback Object registered with a client, will be invoked as appropriate. MqttCallback is an interface that must be implemented by another class...To enable the callback feature, a callback object is registered with a client, this would most logically be done prior to connecting to the server
And after reading the last two lines i mentioned, i got confused.because as far as i understood, the essence of having a client registered to the calback that hasconnectionLost,deliveryComplete,messageArrived
is to handle the server states "asynchronously" and read from the server.
Now, my question is, regarding the last two lines i quoted, How i should register a client to read states from the server prior connecting to the server itself? or in other words, "why, "client.callback" should be called prior to "client.connect()"?"
Can anyone please clarify and explain this point.