2013-08-19 55 views
0

用戶添加其他用戶sanika。但是當tester檢查sanika的狀態時,他得到subscribe。爲什麼這樣?爲什麼我獲得「訂閱」狀態?對於<code>sanika</code>被設置爲<strong><em><code>Roster.SubscriptionMode.accept_all</code></em></strong>在他roster.The訂閱模式命名爲<code>tester</code>

在函數main中,sanika設置她的狀態並在函數connectTester測試器中嘗試獲取sanika的狀態。

 public static void main(String[] args) { 
     try { 
      Connection connection = new XMPPConnection("localhost"); 
      connection.connect(); 
      connection.login("sanika", "tester"); 

      Roster r = connection.getRoster(); 

      r.setSubscriptionMode(Roster.SubscriptionMode.accept_all); 

      Presence p = new Presence(Presence.Type.available); 
      p.setStatus("Having Lunch :)"); 

      connection.sendPacket(p); 

      connectTester(); 

      Thread.sleep(30000); 

     } catch(Exception exc) { 
      exc.printStackTrace(); 
      } 
    } 

    public static void connectTester() { 
     try { 
      Connection connection = new XMPPConnection("localhost"); 
      connection.connect(); 
      connection.login("tester", "tester"); 

      Roster r = connection.getRoster(); 
      RosterEntry re = r.getEntry("[email protected]"); 
      System.out.println(re.getStatus().toString()); 
      // PRINTS SUBSCRIBE 

     }catch(Exception exc) {} 

我在哪裏犯了一個錯誤?

注:tester添加sanika爲:

 String group[] = {"Friend List"}; 
     r.createGroup("Friend List"); 
     r.createEntry("[email protected]", "sanika", group); 

回答

0

我兩個用戶添加到每個人名單如下

//subscribe to eachother 
connection.login("tester", ...); 
Presence subscribe = new Presence(Presence.Type.subscribe); 
subscribe.setTo("[email protected]"); 
connection.sendPacket(subscribe); 
connection.disconnect(); 
...     
connection.connect(); 
connection.login("sanika", ...); 
subscribe = new Presence(Presence.Type.subscribe); 
subscribe.setTo("[email protected]"); 
connection.sendPacket(subscribe); 
connection.disconnect(); 

還請注意,你似乎同時使用[email protected][email protected](中第一個login-main的陳述)

+0

我發佈了一個查詢..如果我們可以在這裏討論它http://chat.stackoverflow.com/rooms/40703/discussion-between-suhail-and-marc-van-daele –

+0

我發佈了一個查詢那裏 –

相關問題