Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6965709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:05:47+00:00 2026-05-27T16:05:47+00:00

I have the following code in android – I’m using asmack API. public XMPPManager(String

  • 0

I have the following code in android – I’m using asmack API.

 public XMPPManager(String server, int port) {
    this.server = server;
    this.port = port;

    SmackConfiguration.setPacketReplyTimeout(packetReplyTimeout);
    config = new ConnectionConfiguration(server, port);
    config.setSASLAuthenticationEnabled(false);
    config.setSecurityMode(SecurityMode.disabled);
    connection = new XMPPConnection(config);
    try {
      connection.connect();
      connection.login(user, pass);
    } catch (XMPPException e) {
      Log.w("Cannot connect to server.", "0");
      e.printStackTrace();
    }
    if (connection.isAuthenticated()) {
      AccountManager manager = connection.getAccountManager();
      try {
        manager.createAccount("test", "test");
      } catch (XMPPException e) {
        Log.w("Cannot create new user -----" + " on the XMPP server.", "0");
      }
    }

  }

I’m creating an instance of the XMPPManager class in an XMPPClient activity like this:

public class XMPPClient extends Activity {
  private String username = "user";
  private String password = "pass";
  private String host     = "127.0.0.1";
  private int    port     = 5222;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    try {
      super.onCreate(savedInstanceState);

      XMPPManager xmppManager = new XMPPManager(host, port);
    } catch (Exception e) {

    }
  }

}

The problem I’m getting is the following:

W/Cannot connect to server.( 1052): 0
W/System.err( 1052): XMPPError connecting to 127.0.0.1:5222.: remote-server-error(502) XMPPError connecting to 127.0.0.1:5222.
W/System.err( 1052):   -- caused by: java.net.ConnectException: /127.0.0.1:5222 - Connection refused
W/System.err( 1052):    at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:562)
W/System.err( 1052):    at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:991)
W/System.err( 1052):    at company.games.boxer.XMPPManager.<init>(XMPPManager.java:45)
W/System.err( 1052):    at company.games.boxer.XMPPClient.onCreate(XMPPClient.java:17)
W/System.err( 1052):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err( 1052):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
W/System.err( 1052):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
W/System.err( 1052):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
W/System.err( 1052):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
W/System.err( 1052):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 1052):    at android.os.Looper.loop(Looper.java:123)
W/System.err( 1052):    at android.app.ActivityThread.main(ActivityThread.java:4627)
W/System.err( 1052):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 1052):    at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err( 1052):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
W/System.err( 1052):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
W/System.err( 1052):    at dalvik.system.NativeStart.main(Native Method)
W/System.err( 1052): Nested Exception:
W/System.err( 1052): java.net.ConnectException: /127.0.0.1:5222 - Connection refused
W/System.err( 1052):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:254)
W/System.err( 1052):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
W/System.err( 1052):    at java.net.Socket.connect(Socket.java:1055)
W/System.err( 1052):    at java.net.Socket.connect(Socket.java:997)
W/System.err( 1052):    at org.jivesoftware.smack.proxy.DirectSocketFactory.createSocket(DirectSocketFactory.java:28)
W/System.err( 1052):    at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:550)
W/System.err( 1052):    at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:991)
W/System.err( 1052):    at company.games.boxer.XMPPManager.<init>(XMPPManager.java:45)
W/System.err( 1052):    at company.games.boxer.XMPPClient.onCreate(XMPPClient.java:17)
W/System.err( 1052):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err( 1052):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
W/System.err( 1052):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
W/System.err( 1052):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
W/System.err( 1052):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
W/System.err( 1052):    at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err( 1052):    at android.os.Looper.loop(Looper.java:123)
W/System.err( 1052):    at android.app.ActivityThread.main(ActivityThread.java:4627)
W/System.err( 1052):    at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 1052):    at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err( 1052):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
W/System.err( 1052):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
W/System.err( 1052):    at dalvik.system.NativeStart.main(Native Method)

Any ideas why I’m receiving the “Cannot connect to server.” error? Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:05:48+00:00Added an answer on May 27, 2026 at 4:05 pm

    I think this line,

    private String host = "127.0.0.1";
    

    is cause exception.. So try..

    private String host = "10.0.2.2"; or System’s public IP

    Bco’z Android doesn’t understand 127.0.0.1 ip of your system as a local host, this ip is for emulator itself..(loop back address)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi all I have created layout using following code <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I am developing a Android app using Jquery Mobile/Phonegap. I have the following code
I have the following code for Android which works fine to play a sound
I have the following code running on my Android device. It works great and
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
Android:How to display images from the web in a ListView?I have the following code
I have created an application that creates notifications, using the following code: // notification
I have the following code in my application in res/xml/preferences.xml: <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=Wi-Fi
I have the following code in a WCF Service that returns a string, and
I have the following code populating a spinner, JSONObject jsonResponse = new JSONObject(new String(buffer));

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.