Android xmpp error host-unknown

时间:2016-07-11 19:11:20

标签: java android xmpp smack

I'm trying to make a connection to xmpp server and this returning me this error.

W/AbstractXMPPConnection: Connection closed with error org.jivesoftware.smack.XMPPException$StreamErrorException: host-unknown You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1003) at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:944) at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:959) at java.lang.Thread.run(Thread.java:818)

I tried to use this example in github and put this data.

private static final String DOMAIN = "10.20.0.125"; 

private static final String HOST = "10.20.0.125"; 

private static final int PORT = 5222;

private String userName ="admin2@localhost";

private String passWord = "asdfasdf";

The server is ok, we conducted another test pc to make a communication on android but this error persists.

2 个答案:

答案 0 :(得分:0)

我主要看到2个错误:

在演示配置中,您有以下代码行:

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
    configBuilder.setUsernameAndPassword(userName, passWord);
    configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    configBuilder.setResource("Android");
    configBuilder.setServiceName(DOMAIN);
    configBuilder.setHost(HOST);
    configBuilder.setPort(PORT);

第一个问题(主要问题): DOMAIN变量应该(但必须)是您可以在服务器配置中读取的服务器名称,而不仅仅是IP;一些功能将在本地主机之外发生。

第二个问题: 虽然我建议从配置中分离登录(所以只需配置连接然后登录)我没有得到它的用户名: localhost 将无法在服务器机器外解析,所以再次必须替换为DOMAIN名称(即使理论上,连接会给用户他的域名,也不需要如此明确)。

这样:

 connection.connect();
 login();

将替换为

 connection.connect();
 login(userName ,passWord,"Android" );

你需要删除这2行:

configBuilder.setResource("Android");
configBuilder.setUsernameAndPassword(userName, passWord);

关于DOMAIN名称:您可以在服务器配置中找到它,在Openfire中它是"服务器名称"您可以在“服务器信息”页面中的Web界面中阅读。

答案 1 :(得分:0)

我设法找到了解决方案。 我使用.jar文件而不是编译gradle依赖项:

compile 'org.igniterealtime.smack:smack-android:4.1.4'
compile 'org.igniterealtime.smack:smack-tcp:4.1.4'
compile 'org.igniterealtime.smack:smack-im:4.1.4'
compile 'org.igniterealtime.smack:smack-extensions:4.1.4'

因此错误已经解决。谢谢你的帮助。