如何与Smack客户端Android建立Ejabberd连接?

如何与Smack客户端Android建立Ejabberd连接?,android,ejabberd,smack,Android,Ejabberd,Smack,SMACKException:以下地址失败:“localhost:5222”失败,因为java.net.ConnectException:在30000ms后未能连接到localhost/127.0.0.1(端口5222):断开连接失败:EconRefused(连接被拒绝) 请帮我一下。由于您尚未指定要从设备或emulator连接到服务器,我想您是在emulator中使用应用程序,所以请提前感谢 如果您从Android emulator引用系统上的本地主机,则必须使用,因为Android emul

SMACKException:以下地址失败:“localhost:5222”失败,因为java.net.ConnectException:在30000ms后未能连接到localhost/127.0.0.1(端口5222):断开连接失败:EconRefused(连接被拒绝)


请帮我一下。由于您尚未指定要从设备或emulator连接到服务器,我想您是在emulator中使用应用程序,所以请提前感谢

如果您从Android emulator引用系统上的本地主机,则必须使用,因为Android emulator在虚拟机中运行,因此这里127.0.0.1或localhost将是emulator自己的环回地址

参考:

看看这个答案:

   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);