1

我写了以下代码:

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);在连接和登录之间使用一些延迟就可以了。但它不起作用!

4

1 回答 1

0

你有代理或防火墙吗?检查您与 smack 端口的连接。

在这个博客中有一个 gtalk 连接的例子,它使用 SASLAuthentication 类来进行 TSL 身份验证。 http://ashwinrayaprolu.wordpress.com/2011/05/03/smack-xmpp-and-gtalk/

SASLAuthentication:http ://www.igniterealtime.org/builds/smack/docs/3.2.2/javadoc/org/jivesoftware/smack/SASLAuthentication.html

祝你好运。

于 2013-03-28T02:46:25.740 回答