title: MQTT - Is there a way to check if the client is still connected
body: <p>Is there a way to check if the client is still connected to the MQTT broker? </p>
  
  <p>Something like </p>
  
  <pre><code>if client.isConnected(): # for example
      # if True then do stuff
  </code></pre>
  
  <p>Edit: There was instance where my Raspberry Pi stopped receiving from the client although it was still (from the look of it, the code was still showing updated results) running. </p>
  
  <p>Here is the code since I may be doing something wrong:</p>
  
  <pre><code>client = mqtt.Client()
  client.connect(address, 1883, 60)
  
  while True:
      data = getdata()
      client.publish("$ahmed/",data,0)
      time.sleep(0.2)
  </code></pre>
  
  <p>The thing is that I was away, so I am not even sure why it stopped! Only if I restart my broker then it will start receiving again.</p>