我正在使用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)
但是当我检查ejabbard时,为用户启动了服务器会话。还使用converse.js我可以验证用户是否已登录。
所以我觉得我没有得到smack的回应。
答案 0 :(得分:0)
查看SMACK关于创建连接的文档,您错过了对connection.login()
的调用,因此它会在5秒后超时。 (参见最后2条RECV消息之间的差值)
文档:https://download.igniterealtime.org/smack/docs/latest/documentation/connections.html