2015-04-07 20 views
4

環境時拋出:

  • 服務器: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),但是這在我的情況下沒有奏效。

從調試輸出看來,服務器發送挑戰,客戶端忽略它。

任何幫助,將不勝感激。

+1

你閱讀和遵守https://github.com/igniterealtime/Smack/wiki/Smack-4.1-Readme-中的說明:那麼,通過實現ConnectionListener界面如下方式使用回調方法連接和升級指南? – Flow

+0

我確實讀過,沒有發現任何非常有趣的東西。雖然爲了盡職盡責,我嘗試改變自己的模式來模仿你發送的鏈接中代表的內容,並且看到它現在起作用。 感謝您的回覆 –

+5

請回答您自己的問題,解釋您做錯了什麼,並將答案標記爲已接受。 – Flow

回答

0

對於我而言,我刪除下面的扶養在我的pom.xml

然後,錯誤沒有再露面。

<dependency> 
     <groupId>org.igniterealtime.smack</groupId> 
     <artifactId>smack-extensions</artifactId> 
     <version>4.1.4</version> 
    </dependency> 
-1

當您調用connect()時,將建立使用smack的Xmpp連接。但它只是啓動連接過程。連接將在後臺建立(單獨的線程)。

在你的情況下,你在connect()語句之後登錄到xmpp服務器。到那時登錄語句被執行,連接可能不會被建立。

XMPPTCPConnection connection = new XMPPTCPConnection(config); 
    connection.addConnectionListener(new ConnectionListener() { 

     @Override 
     public void reconnectionSuccessful() { 
     } 

     @Override 
     public void reconnectionFailed(Exception arg0) { 
     } 

     @Override 
     public void reconnectingIn(int arg0) { 
     } 

     @Override 
     public void connectionClosedOnError(Exception arg0) { 
     } 

     @Override 
     public void connectionClosed() { 
     } 

     @Override 
     public void connected(XMPPConnection arg0) { 
      System.out.println("Connected to xmpp service...."); 
      try { 
       connection.login("username", "password"); 
       System.out.println("Logged in to xmpp service...."); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 

     } 

     @Override 
     public void authenticated(XMPPConnection arg0, boolean arg1) { 
      // TODO Auto-generated method stub 

     } 
    }); 
    connection.connect(); 
+1

答案是錯誤的:'connect()'是一個同步調用。 – Flow

+0

感謝您的反饋@Flow。調用login()後跟connect()應該可以工作。爲什麼它不起作用? – Vamshi

+0

我說'connect()'是一個同步調用,你說它是異步的(例如,「...當你調用connect(),但它只是啓動連接過程,連接將建立在後臺..」),因此你建議在連接監聽器中調用'login()'。但這不是必需的,因此這個答案的建議是不需要的。 – Flow