我正在尝试连接到我的公司 XMPPServer 并得到以下异常:
java.io.EOFException: input contained no data
at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:3003)
at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046)
at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1410)
at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
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)
我的代码真的很基本......
System.setProperty("smack.debugEnabled", "true");
XMPPConnection.DEBUG_ENABLED = true;
ConnectionConfiguration config = new ConnectionConfiguration("xxx", 5223);
config.setSecurityMode(SecurityMode.enabled);
config.setSASLAuthenticationEnabled(true);
config.setDebuggerEnabled(true);
config.setCompressionEnabled(false);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
我究竟做错了什么?
Smack Debug 窗口中的“Raw Sent Packets”似乎显示了正确的 xml 流:
<stream:stream to="xxx" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<presence id="3347O-0" type="unavailable"></presence>
</stream:stream>
- - 更新 - -
我发现了这个问题。
对于 SSL 连接,需要以下代码:
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
config.setSocketFactory(new DummySSLSocketFactory());
DummySSLSocketFactory 类可以在 Spark 中找到,也可以直接在此处找到: