Getting SocketTimeoutException when 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. when running smackClient program I get 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

      

Connecting to the same ejabberd server using the same android device works fine using xmpp clients like xabber. so the problem is of course with the client code I wrote. Below is a 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);

      

My client code is missing something like xabber, so the xabber connection works from the same device using the same credentials.

Please, help

+3


source to share


3 answers


It's hard to tell without real IP addresses and names in your example. However, my best guess would be how your server IP address is resolved.

Your example seems to have a mismatch with the server (example.com) and the service name in your code (abc.example.com).

I am assuming that your client is trying to connect to another machine that is running the XMPP server.



So, here's what to check when you have problems with a server not responding:

  • Check how the domain address is resolved. You may need to specify a different machine name, which is the domain. If this is a test domain, there might not be a DNS setting, so you might even need to specify the server IP (while still configuring the client to use the XMPP domain, these are two different things).
  • In the client, register the IP address you are trying to connect to to make sure this is where the server is running.
  • If the server is not on the main domain server, you may need to perform DNS SRV queries for the C2S XSLP service.
0


source


It took me several hours to find a solution.

I forgot to turn off the VPN (Express VPN) app . The main reason was network tunneling.

And change the properties of the network protocol version as shown below,



enter image description here

Select the first option (automatically obtain the DNS server address).

0


source


My experience: I used the 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 failed to connect and threw a connection timeout exception. When I disabled Windows Firewall, it worked correctly and connected.

0


source







All Articles