smack 中 XMPPConnection 的登录方法发生异常
Posted
技术标签:
【中文标题】smack 中 XMPPConnection 的登录方法发生异常【英文标题】:Exception occurred on login method of XMPPConnection in smack 【发布时间】:2013-03-27 23:36:58 【问题描述】:我写了以下代码:
ConnectionConfiguration connConfig = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(connConfig);
connection.connect();
System.in.read();
connection.login("xxx@gmail.com", "***"); //Exception occurs here!
例外是
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:185)
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)Exception in thread "main" No response from the server.:
at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:73)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:212)
at org.jivesoftware.smack.Connection.login(Connection.java:348)
有时我也会遇到这个异常:
Exception in thread "main" Connection failed. No response from server.:at org.jivesoftware.smack.PacketReader.startup(PacketReader.java:119)
at org.jivesoftware.smack.XMPPConnection.initConnection(XMPPConnection.java:568)
at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:527)
at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:953)
有人可以帮助我吗?我用谷歌搜索,有人说如果你在连接和登录之间使用Thread.sleep(10000);
延迟一些就可以了。但它不起作用!
【问题讨论】:
【参考方案1】:您有代理或防火墙吗? 检查您与 smack 端口的连接。
在这个博客中有一个 gtalk 连接的例子,它使用 SASLAuthentication 类来进行 TSL 身份验证。 http://ashwinrayaprolu.wordpress.com/2011/05/03/smack-xmpp-and-gtalk/
SASL 身份验证:http://www.igniterealtime.org/builds/smack/docs/3.2.2/javadoc/org/jivesoftware/smack/SASLAuthentication.html
祝你好运。
【讨论】:
不,我在 Ubuntu 中开发,没有任何代理!有什么想法吗? 在我的回答中有一个示例 gmail 使用 tsl auth 的链接 好的,我会尝试并尽快回复您。 :-)以上是关于smack 中 XMPPConnection 的登录方法发生异常的主要内容,如果未能解决你的问题,请参考以下文章
aSmack连接server异常smack.SmackException$ ConnectionException thrown by XMPPConnection.connect();