Asmack 18连接:google.com:5222异常:无法连接到远程talk.google.com服务器超时连接到、异常、服务器、google

2023-09-06 09:16:42 作者:┕天生的王者

我想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

  

静态code

    

为了在Android上正常工作,您需要注册啪的  XMPP提供商和手动扩展和初始化一些静态code  你以前块做任何XMPP activty。调用   SmackAndroid.init(上下文)(适用于org.jivesoftware.smack)将做到这一点  给你的。

  SmackAndroid.init(getApplicationContext());    ConnectionConfiguration connConfig =新ConnectionConfiguration(talk.google.com,5222,gmail.com);... 
为什么我的TIA Portal 博途 V13 显示 许可证wincC COMFORT 无效 请安装有效的许可证密钥

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

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

.