我写了以下代码:
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);
延迟一些就行了。但它不起作用!
答案 0 :(得分:0)
你有代理或防火墙吗? 检查你与smack端口的连接。
在这个博客中有一个gtalk连接的例子,它使用SASLAuthentication类来进行TSL的autenthication。 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
祝你好运。