Asmack 18 connection : google.com:5222 Exception: Could not connect to talk.google.com remote-server-timeout

喜欢而已 提交于 2019-12-23 00:52:34

问题


I am trying to use asmack 18 to connect to gtlak server for XMPP connection.

public static final String HOST = "talk.google.com";
public static final int PORT = 5222;
public static final String SERVICE = "gmail.com";

ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST, PORT, SERVICE);
    XMPPConnection connection = new XMPPConnection(connConfig);

    try {
      //Connect to the server
      connection.connect();
      connection.login("xxxxxxxx@gmail.com", "password");
    // Set the status to available
      Presence presence = new Presence(Presence.Type.available);
      connection.sendPacket(presence);
      //xmppClient.setConnection(connection);
      Log.d("connection","connection successfull");
    } catch (XMPPException ex) {
      connection = null;
      Log.d("connection","connection fail");
      //Unable to connect to server
    }

But it gives timeout error. talk.google.com:5222 Exception: Could not connect to talk.google.com:5222.; : remote-server-timeout(504) -- caused by: java.net.UnknownHostException: talk.google.com


回答1:


Read the ReadME =) http://asmack.freakempire.de/0.8.9/README

Static Code

In order to work correctly on Android, you need to register Smack's XMPP Providers and Extensions manually and init some static code blocks before you doing any XMPP activty. Calling SmackAndroid.init(Context) (in org.jivesoftware.smack) will do this for you.

    SmackAndroid.init(getApplicationContext());
    ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
...

.



来源:https://stackoverflow.com/questions/20288633/asmack-18-connection-google-com5222-exception-could-not-connect-to-talk-goog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!