【问题标题】:How to make Ejabberd connection with Smack client Android?如何使 Ejabberd 与 Smack 客户端 Android 连接?
【发布时间】:2016-07-22 02:10:17
【问题描述】:

SMACKException:以下地址失败:'localhost:5222' 失败,因为 java.net.ConnectException:30000 毫秒后无法连接到 localhost/127.0.0.1(端口 5222):isConnected 失败:ECONNREFUSED(连接被拒绝)

   XMPPTCPConnectionConfiguration.Builder config =     
   XMPPTCPConnectionConfiguration
            .builder();
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    config.setServiceName("localhost");
    config.setHost("localhost");
    config.setPort(5222);
    config.setDebuggerEnabled(true);
    XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true);
    XMPPTCPConnection.setUseStreamManagementDefault(true);
    connection = new XMPPTCPConnection(config.build());
    XMPPConnectionListener connectionListener = new     
    XMPPConnectionListener();
    connection.addConnectionListener(connectionListener);

请帮帮我。提前致谢

【问题讨论】:

    标签: android ejabberd smack


    【解决方案1】:

    由于您没有指定您是从设备或模拟器连接到服务器,我猜您正在模拟器中使用您的应用程序。

    如果您从 Android 模拟器引用系统上的 localhost,那么您必须使用 http://10.0.2.2:8080/,因为 Android 模拟器在虚拟机中运行,因此此处 127.0.0.1 或 localhost 将是模拟器自己的环回地址。

    参考:http://developer.android.com/tools/devices/emulator.html#emulatornetworking

    看到这个答案:java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 2017-11-25
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多