我正在使用 smack 连接 ejabbard 服务器。
使用以下代码通过 smack 连接 ejabbard 服务器
val config=XMPPTCPConnectionConfiguration.builder()
.setXmppDomain(mDomainName)
.setUsernameAndPassword(mUsername,mPassword)
.setDebuggerEnabled(true)
mConnection= XMPPTCPConnection(config.build())
Log.v("Current status ",mConnection!!.isConnected().toString())
mConnection!!.connect()
但最终得到错误/警告:
4-15 12:09:22.626 2685-3195/com.example.itstym.kotlinchat I/DNSUtil: Could not resolve DNS SRV resource records for _xmpp-client._tcp.replica3377.cloudapp.net. Consider adding those.
04-15 12:09:23.033 2685-3208/com.example.itstym.kotlinchat D/SMACK: SENT (1): <stream:stream xmlns='jabber:client' to='replica3377.cloudapp.net' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='user2@replica3377.cloudapp.net' xml:lang='en'>
04-15 12:09:23.189 2685-3209/com.example.itstym.kotlinchat D/SMACK: RECV (1): <?xml version='1.0'?><stream:stream id='3002662766383892485' version='1.0' xml:lang='en' xmlns:stream='http://etherx.jabber.org/streams' to='user2@replica3377.cloudapp.net' from='replica3377.cloudapp.net' xmlns='jabber:client'>
04-15 12:09:23.190 2685-3209/com.example.itstym.kotlinchat D/SMACK: RECV (1): <stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>X-OAUTH2</mechanism><mechanism>SCRAM-SHA-1</mechanism></mechanisms></stream:features>
04-15 12:09:28.846 2685-2754/com.example.itstym.kotlinchat D/SMACK: RECV (0): <stream:error><connection-timeout xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error></stream:stream>
大约 30 秒后我收到另一个错误
04-15 12:09:28.853 2685-2754/com.example.itstym.kotlinchat W/AbstractXMPPConnection: Connection XMPPTCPConnection[not-authenticated] (0) closed with error
org.jivesoftware.smack.XMPPException$StreamErrorException: connection-timeout You can read more about the meaning of this stream error at http://xmpp.org/rfcs/rfc6120.html#streams-error-conditions
<stream:error><connection-timeout xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1046)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:980)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:996)
at java.lang.Thread.run(Thread.java:818)
但是当我 checkin ejabbard 服务器 session 时,会为用户启动。我还可以使用 converse.js 验证用户是否已登录。
所以我想我没有收到 smack 的回复。
最佳答案
查看 SMACK 关于创建连接的文档,您缺少对 connection.login()
的调用,因此它会在 5 秒后超时。 (查看最后 2 条 RECV 消息之间的增量)
文档:https://download.igniterealtime.org/smack/docs/latest/documentation/connections.html
关于android - 无法得到 smack 的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43423109/