title: How to set the timeout for a MQTT client?
body: <p>I'm using the <a href="http://www-01.ibm.com/support/docview.wss?uid=swg24006006" rel="nofollow">IA92 Java implementation for MQTT</a>, which allows me to connect to a MQTT broker. In order to establish the connection, I'm doing something like this:</p>
  
  <pre><code>// Create connection spec
  String mqttConnSpec = "tcp://the_server@the_port";
  // Create the client and connect
  mqttClient = MqttClient.createMqttClient(mqttConnSpec, null);
  mqttClient.connect("the_id", true, 666);
  </code></pre>
  
  <p>The problem is that sometimes the server takes too much time to send a response, and it throws a timeout exception:</p>
  
  <pre><code>org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocket(OSNetworkSystem.java:130)
    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:246)
    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
    at java.net.Socket.connect(Socket.java:1055)
    at com.ibm.mqtt.j2se.MqttJava14NetSocket.&lt;init&gt;((null):-1)
    at com.ibm.mqtt.j2se.MqttJavaNetSocket.setConnection((null):-1)
    at com.ibm.mqtt.Mqtt.tcpipConnect((null):-1)
    at com.ibm.mqtt.MqttBaseClient.doConnect((null):-1)
    at com.ibm.mqtt.MqttBaseClient.connect((null):-1)
    at com.ibm.mqtt.MqttClient.connect((null):-1)
    at com.ibm.mqtt.MqttClient.connect((null):-1)
  </code></pre>
  
  <p>What I need to do is setting a timeout manually, instead of letting the mqtt client decide that. The documentation says: <em>There are also methods for setting attributes of the MQ Telemetry Transport connection, such as timeouts and retries.</em></p>
  
  <p>But, honestly, I haven't found anything about it. I have taken a look at the whole javadoc reference and there's no evidence of timeout configuration. I can't see the source code since it's not open source.</p>
  
  <p>So how can I set the timeout for the Mqtt connection?</p>