I'm very new to mqtt c++ client.
i have a mqtt::async_client (documentation here) client with automatic reconnect options that I want to test but I am having difficulties in inducing a connection loss or connection interruptions.
Consider the following
   /* mqtt async client connecting to localhost with 
     port 1833 and is called "client_name"
   */
   mqtt::async_client cli("localhost", 1883, "client_name");
   const mqtt::connect_options conOp;
   /* set options to automatically reconnect after a connection loss(?)
      at every 10 seconds interval upto 40 seconds
   */
   conOpt.set_automatic_reconnect(10, 40);
  
   /* establish the connection */
   cli.connect(conOp);
   /* induce connection interruption for 42 seconds? */
   cli.interrupt_connection(42); //how to do this?
   
   bool isConnected = true;
   isConnected = cli->is_connected();
   std::cout << "Is the client connected ? "<< isConnected << "\n";
stdcout should be false since the connection could not be established.
Any suggestions will be really helpful. Thanks in advance
Aucun commentaire:
Enregistrer un commentaire