Search code examples
xmppejabberdsmack

getting SocketTimeoutException while using smack 4.1.2 in android to connect to my ejabberd server


I am trying to connect to ejabberd server using smack API 4.1.2 (no asmack) on android device. while running smackClient program , I am getting below error

java.net.SocketTimeOutException:Failed to connect to abc.example.com/182.*.*.* (on port 5222) after 30000ms,'abc.example.com:5222' failed because java.net.ConnectionException: Failed to connect to abc.example.com/182.*.*.* (on port 5222) after 30000ms

Connection to same ejabberd server using same android device is working fine using xmpp clients like xabber. so Issue is surely with client code I have written. Below is the snippet of my code

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(userName, password)
.setServiceName("abc.example.com")
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setSendPresence(true)
.build(); 
connection = new XMPPTCPConnection(config);
connection.connect();
connection.login(userName, password);

I am missing something in my client code that xabber is having so xabber connection is working from same device using same credential.

Please help


Solution

  • Hard to tell without real IP and names in your example. However, my best guess would be about how the address to your IP server is resolved.

    There seems to be discrepancy in your example with server (example.com) and service name in your code (abc.example.com).

    My guess it that your client is attempting to connect to another machine that the one the XMPP server is running on.

    So, here are the things to check when you have issues with a server not replying:

    • Check how the address of the domain is resolved. You may need to specify another machine name that the domain. If this is a test domain, there is possibly not a DNS setup, so you may even need to specify server IP (while still configuring the client to use an XMPP domain, that's two different things).
    • In client, log the IP you are trying to connect to, to make sure this is the one where the server is running.
    • If server is not on the main domain server, you may even need to do DNS SRV record queries for XMPP C2S service.