簡體   English   中英

如何與 Smack 客戶端 Android 建立 Ejabberd 連接?

[英]How to make Ejabberd connection with Smack client Android?

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 模擬器引用系統上的 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 denied

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM