-1

I'm trying to connect to openfire/ejabberd(I have both of them configured and tested for connection with strophe.js) on localhost using smack. This is what I've tried:

Log.d(TAG, "Connecting to server " + mServiceName);
            XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
            config.setUsernameAndPassword("test_user1@home", "password");
            config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
            config.setServiceName("home");
            config.setHost("127.0.0.1");
            config.setPort(5222);
            config.setCompressionEnabled(true);
            config.setDebuggerEnabled(true);
            final XMPPTCPConnection xmpptcpConnection = new XMPPTCPConnection(config.build());
            SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");

            mConnection = new XMPPTCPConnection(config.build());
            mConnection.setPacketReplyTimeout(10000);
            mConnection.addConnectionListener(this);
            mConnection.connect();
            mConnection.login();

but I get back:

 org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: '127.0.0.1:5222' failed because java.net.ConnectException: failed to connect to /127.0.0.1 (port 5222) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)

I'm using my phone to connect. I assume that this is happening because it is not registered on the internet. I've purchased a domain and created a subdomain, but I have no idea on how to register my openfire/ejabberd server with that.

If anything is as it should with the builder configuration could anybody give me some intructions on how to register it?

Edit: To register openfire on a public account I have to enable ssh and do some configuration(I would rather not). Isn't there any way to test my android app on my local account?

Bogdan Daniel
  • 2,689
  • 11
  • 43
  • 76

3 Answers3

1

You are using IP 127.0.0.1. This means the local IP address of the local computer. Running that from your phone means that you are not trying to connect to the XMPP server on your computer, but on an XMPP server on your phone.

It cannot work. You need to use the IP address of your computer.

Mickaël Rémond
  • 9,035
  • 1
  • 24
  • 44
  • my openfire is installed locally on my PC. It is giving me SmackException: exception: java.net.SocketTimeoutException: failed to connect to "my local IP address". Can you please give some advice regarding this issue? Thanks – Kaveesh Kanwal Nov 08 '16 at 04:53
0

if you haven't found answer for your question. Try to use this host 10.0.2.2 instead of your's one(127.0.0.1). This solves "Connection refused".

Steve
  • 81
  • 2
  • 10
-1

You are using IP 127.0.0.1 which is the local IP address of the local computer.It cannot work. we have to use the IP address of our computer.