4

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

Kartik Patel
  • 479
  • 1
  • 4
  • 19

3 Answers3

0

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.
Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
  • Hi Remond, thanks for your quick post. I can't share domain name due to privacy reasons but, i admin that i manually typed in exception due to eclipse not allowing copy-paste and did typo there. I updated exception now. i also wrote small code to show DNSResolver is resolving to correct address. `List address = DNSUtil.resolveXMPPDomain("abc.example.com", null); if(address!=null && address.size()>0) { System.out.println(address.get(0).getPort() +"&"+ address.get(0).getFQDN()); }` output: 5222 & abc.example.com. what can go wrong here? – Kartik Patel Aug 02 '15 at 11:10
  • If you can connect on ejabberd with another client, this is not ejabberd nor firewall issue. The issue seems to be clearly tcp level (no tcp session established). The only reasons I can think of is either connecting on incorrect IP or incorrect port. – Mickaël Rémond Aug 02 '15 at 11:35
  • Remand, as usual you are spot on. My internal local ip got changed from 192.168.1.4 to 192.168.1.5 so hat had caused issue. Finally managed to get it working. Thanks a lot for your help – Kartik Patel Aug 06 '15 at 17:15
  • Thank you for your kind words ! – Mickaël Rémond Aug 06 '15 at 17:17
0

For me , it took hours to find the solution.

I forget to turnoff the VPN application(Express VPN) .Network tunneling was the root cause .

And change the Network protocol version properties as below ,

enter image description here

Choose the 1st option (Obtain DNS server address automatically).

Don Chakkappan
  • 7,397
  • 5
  • 44
  • 59
0

My experience: I used following code

DomainBareJid xmppServiceDomain = JidCreate.domainBareFrom("desktop-urvfr83");
            //DomainBareJid xmppServiceDomain = JidCreate.domainBareFrom("192.168.1.3");
            InetAddress addr = InetAddress.getByName("192.168.1.3");

            XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                    .setUsernameAndPassword("alir", "111111")
                    .setHostAddress(addr)
                    .setResource("phonn")
                    .setXmppDomain(xmppServiceDomain)
                    .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                    .setPort(5222)
                    .build();

but it could not connect and produced timeout connection exception. When I disabled windows firewall it worked correctly and connected.

M Shafaei N
  • 409
  • 3
  • 6