Smack API,connect() 异常
我正在尝试连接到我公司的 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 调试窗口中的“原始发送数据包”似乎显示了正确的 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 中找到或直接在此处找到:
I'm trying to connect to my company XMPPServer and get the following exception:
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)
My code is really basic...
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();
What am I doing wrong?
The "Raw Sent Packets" from the Smack Debug window seem to display the right xml flow:
<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>
---- UPDATE ----
I found the issue.
For SSL connection the following code is needed:
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
config.setSocketFactory(new DummySSLSocketFactory());
The DummySSLSocketFactory class can be found in Spark or directly here:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了这个问题。
对于 SSL 连接,需要以下代码:
您可以使用 DummySSL 类,在 Spark 中也可以找到。
I found the issue.
For SSL connection the following code is needed:
You can use the DummySSL class, which can also be found in Spark.