XMPP 服务器连接错误

XMPP Server Connection Error

成功登录 XMPP 服务器后出现错误。请告诉我。提前致谢。

错误:java.lang.IllegalArgumentException:服务器时间不是 org.jivesoftware.smack.packet.Message$Type

中的常量
D/SMACK﹕ RECV (0): <message from='sujewan@50.26.201.39/Smack' to='sujewan@50.26.201.39/Smack' type='servertime' timestamp='1439287908'/><presence from='sujewan@50.26.201.39/Smack' to='sujewan@50.26.201.39/Smack' xml:lang='en' id='I0TA4-8'><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.igniterealtime.org/projects/smack' ver='NfJ3flI83zSdUDzCEICtbypursw='/></presence>

W/AbstractXMPPConnection﹕ Connection closed with error
        java.lang.IllegalArgumentException: servertime is not a constant in org.jivesoftware.smack.packet.Message$Type
                at java.lang.Enum.valueOf(Enum.java:200)
                at org.jivesoftware.smack.packet.Message$Type.valueOf(Message.java:607)
                at org.jivesoftware.smack.packet.Message$Type.fromString(Message.java:644)
                at org.jivesoftware.smack.util.PacketParserUtils.parseMessage(PacketParserUtils.java:229)
                at org.jivesoftware.smack.util.PacketParserUtils.parseStanza(PacketParserUtils.java:151)
                at org.jivesoftware.smack.AbstractXMPPConnection.parseAndProcessStanza(AbstractXMPPConnection.java:947)
                at org.jivesoftware.smack.tcp.XMPPTCPConnection.access0(XMPPTCPConnection.java:139)
                at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:982)
                at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access0(XMPPTCPConnection.java:937)
                at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.run(XMPPTCPConnection.java:952)
                at java.lang.Thread.run(Thread.java:818)

这似乎发生在客户端收到一个 <message/> 节,其中 type 属性具有非标准值 servertime:

<message from='sujewan@50.26.201.39/Smack'
         to='sujewan@50.26.201.39/Smack'
         type='servertime'
         timestamp='1439287908'/>

Section 5.2.2 of RFC 6121 说:

If an application receives a message with no 'type' attribute or the application does not understand the value of the 'type' attribute provided, it MUST consider the message to be of type "normal" (i.e., "normal" is the default).

所以这是 Smack 中的一个错误:它不应该在非标准类型值上崩溃。这应该报告给 Smack 开发人员。


另一方面,servertime 消息是扩展 XMPP 的一种不寻常的方式。同一个 RFC 部分说:

If included, the 'type' attribute MUST have one of the following values:

因此不允许将 type 设置为 servertime。添加新消息类型的通常方法是嵌入具有特定命名空间的 XML 元素,例如:

<message from='sujewan@50.26.201.39/Smack'
         to='sujewan@50.26.201.39/Smack'>
   <servertime xmlns='servertime' timestamp='1439287908'/>
</message>

(理想情况下,xmlns='servertime' 放置一个由您控制的 HTTP URL。)


另一方面,为了传递时间信息,您可能会发现在 3.4.1 版本中 XEP-0202: Entity Time meets your needs. Support for XEP-0202 was added 到 Smack。