我想asmack使用18连接到gtlak服务器XMPP连接。
公共静态最后弦乐HOST =talk.google.com;公共静态最终诠释PORT = 5222;公共静态最后弦乐SERVICE =gmail.com;ConnectionConfiguration connConfig =新ConnectionConfiguration(主机,端口,服务); XMPPConnection连接=新XMPPConnection(connConfig); 尝试{ //连接到服务器 connection.connect(); connection.login(xxxxxxxx@gmail.com,密码); //将状态设置为可用 presence presence =新的presence(presence.Type.available); connection.sendPacket(presence); //xmppClient.setConnection(connection); Log.d(连接,连接全成); }赶上(XMPPException前){ 连接= NULL; Log.d(连接,连接失败); //无法连接到服务器 }
但它给超时错误。talk.google.com:5222例外:无法连接到talk.google.com:5222; :远程服务器超时(504) - 致:的java.net.UnknownHostException:talk.google.com
解决方案阅读自述=) HTTP ://asmack.freakempire.de/0.8.9/README
为了在Android上正常工作,您需要注册啪的 XMPP提供商和手动扩展和初始化一些静态code 你以前块做任何XMPP activty。调用 SmackAndroid.init(上下文)(适用于org.jivesoftware.smack)将做到这一点 给你的。
SmackAndroid.init(getApplicationContext()); ConnectionConfiguration connConfig =新ConnectionConfiguration(talk.google.com,5222,gmail.com);...
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
解决方案Read the ReadME =) http://asmack.freakempire.de/0.8.9/README
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");
...
.
上一篇:科尔多瓦3.1 Oriention不工作科尔、多瓦、工作、Oriention
下一篇:保存在删除共享preferences或应用程序的重载之间丢失的用户设置应用程序、存在、用户、preferences