简体   繁体   中英

How to make Ejabberd connection with Smack client Android?

SMACKException: The following addresses failed: 'localhost:5222' failed because java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 5222) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)

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

Please help me on it. Thanks in Advance

Since you have not specified your are connecting to server from device or emulator and I guess you are using your application in emulator.

If you are referring your localhost on your system from the Android emulator then you have to use http://10.0.2.2:8080/ Because Android emulator runs inside a Virtual Machine therefore here 127.0.0.1 or localhost will be emulator's own loopback address.

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

See this answer: java.net.ConnectException: localhost/127.0.0.1:8080 - Connection refused

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM