问题
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