環境時拋出:
- 服務器:Openfire的v3.9.3。
- 客戶端操作系統:Linux
- 服務器操作系統:Linux
- 的Java:1.8.0_40
- 啪:嫌核心-4.10,咂嘴-IM-4.1.0,咂嘴-TCP-4.1.0,咂嘴-sasl提供的-4.1.0
這裏是我的測試客戶端代碼:
public class XMPPClientTest
{
public static void main(String[] args)
{
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setHost("xmpp.domain")
.setServiceName("xmpp.domain")
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setDebuggerEnabled(true)
.setResource("Smack-client")
.build();
AbstractXMPPConnection conn1 = new XMPPTCPConnection(config);
try
{
System.out.println("connecting");
conn1.connect();
System.out.println("connected");
System.out.println("logging in");
conn1.login("user", "password");
System.out.println("logged in");
ChatManager chatmanager = ChatManager.getInstanceFor(conn1);
Chat newChat = chatmanager.createChat("[email protected]");
newChat.sendMessage("Goodbye World!");
conn1.disconnect();
}
catch (IOException | SmackException | XMPPException ioe)
{
ioe.printStackTrace();
}
}
}
這裏是輸出
connecting
11:49:40 AM SENT (0): <stream:stream xmlns='jabber:client' to='xmpp.domain' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>
11:49:40 AM RECV (0): <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xmpp.domain" id="3d0a3800" xml:lang="en" version="1.0">
11:49:40 AM RECV (0): <stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/></stream:features>
logging in
11:49:40 AM SENT (0): <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'>=</auth>
11:49:40 AM RECV (0): <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09InhtcHAua2lkY2hlY2suY29tIixub25jZT0iYXpqS2N3UUh3S2RjTTVQeWt4OEo2YmdsM1VoMk9JQkVTallBWXFLOSIscW9wPSJhdXRoIixjaGFyc2V0PXV0Zi04LGFsZ29yaXRobT1tZDUtc2Vzcw==</challenge>
org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). Used filter: No filter used or filter was 'null'.
at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:106)
at org.jivesoftware.smack.SmackException$NoResponseException.newWith(SmackException.java:85)
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:250)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.loginNonAnonymously(XMPPTCPConnection.java:365)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:452)
at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java:427)
at com.forge.label.app.driver.test.XMPPClientTest.main(XMPPClientTest.java:39)
Apr 07, 2015 11:49:45 AM org.jivesoftware.smack.AbstractXMPPConnection callConnectionClosedOnErrorListener
WARNING: Connection closed with error
java.lang.NullPointerException
at org.jivesoftware.smack.util.stringencoder.Base64.decode(Base64.java:86)
at org.jivesoftware.smack.sasl.SASLMechanism.challengeReceived(SASLMechanism.java:229)
at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:328)
at org.jivesoftware.smack.SASLAuthentication.challengeReceived(SASLAuthentication.java:313)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1040)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:937)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:952)
at java.lang.Thread.run(Thread.java:745)
我可以使用像Pidgin這樣的IM客戶端連接到服務器。但是當我嘗試使用Smack庫時,出現上述錯誤。我發現這個問題的唯一「解決方案」是調用XMPPTCPConnectionConfiguration.setSecurityMode(SecurityMode.disabled),但是這在我的情況下沒有奏效。
從調試輸出看來,服務器發送挑戰,客戶端忽略它。
任何幫助,將不勝感激。
你閱讀和遵守https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-中的說明:那麼,通過實現ConnectionListener界面如下方式使用回調方法連接和升級指南? – Flow
我確實讀過,沒有發現任何非常有趣的東西。雖然爲了盡職盡責,我嘗試改變自己的模式來模仿你發送的鏈接中代表的內容,並且看到它現在起作用。 感謝您的回覆 –
請回答您自己的問題,解釋您做錯了什麼,並將答案標記爲已接受。 – Flow