简体   繁体   English

XMPP 服务器,smack API 连接

[英]XMPP Server, smack API connectivity

I am trying to connect to Tigase Server, implement a client in Java using smack API.我正在尝试连接到 Tigase 服务器,使用 smack API 在 Java 中实现客户端。

    ConnectionConfiguration config = new ConnectionConfiguration("192.32.104.93", 5222, "ELVES-D463645");
    Connection connection =  new XMPPConnection(config);
    connection.connect();

When code reaches connect.当代码到达连接时。 I get following stacktrace.我得到以下堆栈跟踪。

stream:error (host-unknown)
    at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:214)
    at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
    at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
No response from the server.: 
    at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:73)
    at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:230)
    at org.jivesoftware.smack.Connection.login(Connection.java:366)
    at com.directv.xmpp.client.poc.FirstClient.main(FirstClient.java:20)
XMPPException Occured while connecting to server No response from the server.

Can anyone please help me find, where am I going wrong.任何人都可以帮我找到,我哪里错了。 Thanks!谢谢!

I found the solution to it.我找到了解决方法。

I was entering the service name and hostname in wrong place.我在错误的地方输入了服务名称和主机名。

and because my server is locally hosted.并且因为我的服务器是本地托管的。 following code stub worked for connection with Tigase Server.以下代码存根适用于与 Tigase 服务器的连接。

ConnectionConfiguration config = new ConnectionConfiguration("localhost", 5222, "yourdomain");

yourdomain shoulde be the domain name which was entered earlier while installation and configuration of the server. yourdomain应该是之前在安装和配置服务器时输入的域名。

Thank you all for your help though.谢谢大家的帮助。

ConnectionConfiguration config = new ConnectionConfiguration("192.32.104.93", 5222, "ELVES-D463645");

The serviceName, third argument of the ConnectionConfiguration constructor , seems to be wrong. ConnectionConfiguration构造函数的第三个参数 serviceName 似乎是错误的。 I would expect something like a domain here (example.com).我希望这里有一个域(example.com)。

You did not even reach the Tigase server.您甚至没有到达 Tigase 服务器。 The error appears to be related to either configuration of the DNS or to parameters you pass to the Smack library.该错误似乎与 DNS 的配置或您传递给 Smack 库的参数有关。 I do not know Smack API but from the error you attach it looks like you provide incorrect hostname, or at least a hostname which does not have a correct DNS entry.我不知道 Smack API,但从您附加的错误来看,您似乎提供了不正确的主机名,或者至少是一个没有正确 DNS 条目的主机名。 This is fine and you should still be able to connect to the server if you can provide IP address as well.这很好,如果您也可以提供 IP 地址,您应该仍然能够连接到服务器。

Try below, or check your XMPP server Authentication setting尝试以下,或检查您的 XMPP 服务器身份验证设置

ConnectionConfiguration config = new ConnectionConfiguration(XMPP_HOST, XMPP_PORT);
config.setCompressionEnabled(false);
config.setSASLAuthenticationEnabled(false);
connection = new XMPPConnection(config);

Here is a code for Smack 4.3.4这是Smack 4.3.4的代码

 XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
                .setHostAddress(InetAddress.getByName(host))
                .setXmppDomain(JidCreate.domainBareFrom(Domain))
                .setUsernameAndPassword("username", "password")
                .setPort(5222) 
                .build();
        AbstractXMPPConnection connection = new XMPPTCPConnection(conf);
        connection.connect();
        connection.login();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM