Server connection error through ejabberd

Hi,

We are building android XMPP client from scratch .
Here are the development system configurations .
Windows 10.
Smack 4.3.1

server configurations:
OS: linux (ubuntu 18).
Server: Ejabberd 19.08
Hosted on system IP : 192.168.4.162 .
Domain: 192.168.4.162 .
JID Format: <user@192.168.4.162>

Here is My Code snippet:

img_continue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(LOGTAG,“User clicked on login”);
Runnable runnable=new Runnable() {
@Override
public void run() {

                    InetAddress addr = null;
                    try {
                        addr = InetAddress.getByName("192.168.4.162"); 
                        System.out.println("addr:"+addr);
                    } catch (UnknownHostException e) {
                        e.printStackTrace();
                    }
                    HostnameVerifier verifier = new HostnameVerifier() {
                        @Override
                        public boolean verify(String hostname, SSLSession session) {
                            return false;
                        }
                    };
                    
                    XMPPTCPConnectionConfiguration connectionConfiguration = null;
                    try{
                        connectionConfiguration = XMPPTCPConnectionConfiguration.builder()
                                .setUsernameAndPassword("alice", "9009")
                                .setXmppDomain("192.168.4.162")
                                .setHostAddress(addr)
                                .setPort(5222).
                                        setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                                .setKeystoreType(null)
                                .build();
                    }catch (XmppStringprepException e){
                        e.printStackTrace();

                    }
                    AbstractXMPPConnection connection = null;
                    connection = new XMPPTCPConnection(connectionConfiguration);
                    connection.addConnectionListener(new ConnectionListener() {
                        @Override
                        public void connected(final XMPPConnection connection) {
                            Log.d(LOGTAG,"chat Application- connected");
                        }

                        @Override
                        public void authenticated(XMPPConnection connection, boolean resumed) {
                            Log.d(LOGTAG,"chat Application-authenticated");
                        }

                        @Override
                        public void connectionClosed() {
                            Log.d(LOGTAG,"chat Application- closed");
                        }

                        @Override
                        public void connectionClosedOnError(Exception e) {
                            Log.d(LOGTAG,"chat Application- connectionClosedOnError");
                        }
                    });
                    ChatManager chatManager= ChatManager.getInstanceFor(connection);
                    chatManager.addIncomingListener(new IncomingChatMessageListener() {
                        @Override
                        public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
                            Log.d(LOGTAG,"Incoming message :" +message.getBody());
                        }
                    });
                    try {
                        connection.connect().login();
                    } catch (XMPPException e) {
                        e.printStackTrace();
                    } catch (SmackException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            };
            Thread connectionThread = new Thread(runnable);
            connectionThread.start();
        }


    });

It is causing this error continuously

  • Could not resolve DNS SRV resource records for _xmpp-client._tcp.192.168.4.162. Consider adding those.

  • SmackException$ConnectionException: The following addresses failed: ‘_xmpp-client._tcp.192.168.4.162:5222’ failed because: org.minidns.hla.ResolutionUnsuccessfulException: Asking for _xmpp-client._tcp.192.168.4.162. IN SRV yielded an error response NX_DOMAIN, ‘192.168.4.162:5222’ failed because: org.minidns.hla.ResolutionUnsuccessfulException: Asking for 192.168.4.162. IN A yielded an error response NX_DOMAIN, ‘192.168.4.162:5222’ failed because: org.minidns.hla.ResolutionUnsuccessfulException: Asking for 192.168.4.162. IN AAAA yielded an error response NX_DOMAIN

Also we are able to connect from gajim through any pc on the server .
2019-08-22

Also we are not able to connect the localhost instance of server hosted on the same machine .

We are working on it since last week . Still not able to get any success.

Please Help!!!

I’d strongly advice you to set up a proper DNS name for your server. Using bare IP addresses is considered bad practice.

Try using setHost("192.168.4.162") instead of setHostName.
Also, but probably unrelated: Why does your verifier always return false?

I think with Smack 4.3.1, he wants to use setHostAddress(InetAddress).

Even if we connect to the server on the same machine whose domain name is set as the “localhost”. It is returning the same response.

Did you use setHostAddress(), if so, with which IP?

we did it the
127.0.0.1

output of the line
InetAddress.getByName(“127.0.0.1”);

is coming: /127.0.0.1
Doesn’t it supposed to be “localhost”?

also using setHostAddress(“127.0.0.1”);

I am encountering this error:
2019-08-26 06:51:19.673 11834-11920/com.example.txtxtalk W/System.err: org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: ‘127.0.0.1:5222’ failed because: /127.0.0.1 exception: java.net.ConnectException: failed to connect to /127.0.0.1 (port 5222) from /127.0.0.1 (port 43458) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)

Please help

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.