Set connection timeout period


I’'ve written some code for connection, its working fine.

XMPPConnection con = new XMPPConnection(“myserver”,5222);

con.login(“name”, “pwd”);

What I wanted to know is that is there any way of setting the timeout period for trying to get the connection. Say I want it to try only of 3 seconds, is it possible through the API ?

You can do that by providing a custom socket factory to the XMPPConnection, this socket factory should build sockets with the desired timeout.

XMPPConnection conn = new XMPPConnection("host", 5222, "serviceName", yourSocketFactory);

I’'m new to Smack, but what about: