XMPP 注销(Smack API)

Posted

技术标签:

【中文标题】XMPP 注销(Smack API)【英文标题】:XMPP Logout (Smack API) 【发布时间】:2011-08-01 19:36:39 【问题描述】:

我正在使用 Smack API 连接到 Openfire 服务器。我已成功创建用户和登录用户,我的问题是我无法使用XMPPConnection.disconnect() 进行注销,此后,在创建帐户或登录另一个用户时,显示以下错误。有人在这种情况下使用过 Smack API 吗?

应用程序在尝试登录同一用户或其他用户时收到此错误:

java.net.SocketException: Socket closed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:146)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:312)
    at sun.security.ssl.InputRecord.read(InputRecord.java:350)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:818)
    at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:775)
    at sun.security.ssl.AppInputStream.read(AppInputStream.java:94)
    at com.jcraft.jzlib.ZInputStream.read(ZInputStream.java:94)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:282)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:324)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:176)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at java.io.BufferedReader.fill(BufferedReader.java:153)
    at java.io.BufferedReader.read1(BufferedReader.java:204)
    at java.io.BufferedReader.read(BufferedReader.java:278)
    at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2992)
    at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046)
    at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1144)
    at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
    at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:325)
    at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)
    at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)
java.io.IOException: Stream closed
    at java.io.BufferedWriter.ensureOpen(BufferedWriter.java:115)
    at java.io.BufferedWriter.write(BufferedWriter.java:220)
    at java.io.Writer.write(Writer.java:157)
    at org.jivesoftware.smack.PacketWriter.writePackets(PacketWriter.java:192)
    at org.jivesoftware.smack.PacketWriter.access$000(PacketWriter.java:40)
    at org.jivesoftware.smack.PacketWriter$1.run(PacketWriter.java:76)
Exception in thread "Smack Packet Reader (0)" java.lang.NullPointerException
    at org.jivesoftware.smack.XMPPConnection.shutdown(XMPPConnection.java:380)
    at org.jivesoftware.smack.PacketReader.notifyConnectionError(PacketReader.java:166)
    at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:332)
    at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)
    at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

【问题讨论】:

我认为这可能与SMACK-278有关 【参考方案1】:

在第二次尝试登录之前尝试再次调用connect:一旦调用disconnect 注销,实际的套接字就会关闭。 connect 应该重新打开它。

【讨论】:

@Ferni,我之前已经尝试过,但仍然是同样的问题。

以上是关于XMPP 注销(Smack API)的主要内容,如果未能解决你的问题,请参考以下文章

使用 Smack API (xmpp) 从 Java 回调 JavaFX

检测用户登录/注销 xmpp google app engine

从 XMPP 注销客户端

XMPP 节告诉客户端注销

如何在 c# 中关闭任何浏览器时从 XMPP 注销?

XMPP框架下微信项目总结授权登陆/注销/注册