2014-02-17 22 views

回答

1

我自己找到了......我很樂意分享它。讓它成爲誰想要這個人有用..

public void RequestLastMessage(JID jabberid) 
    { 
     try 
     { 
      LastIQ iq = new LastIQ(jabberClient1.Document); 
      iq.To = jabberid; 

      iq.Type = jabber.protocol.client.IQType.get; 
      jabberClient1.Tracker.BeginIQ(iq, LastMessage, null); 
     } 
     catch (Exception ex) 
     { 
      DebugLogger.LogRecord(ex.Message + " [ Function: " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Class: XMPPWrapper ]"); 
     } 
    } 

    private void LastMessage(object sender, jabber.protocol.client.IQ iq, object state) 
    { 
     try 
     { 
      if ((iq == null) || (iq.Type != jabber.protocol.client.IQType.result)) 
       return; 
      Last ll = iq.Query as Last; 
      if (iq.From != null && ll.Message != "") 
       if (ApplicationVariables.GlobalContactForm != null) ApplicationVariables.GlobalContactForm.SetOfflineStatus(ll.Message, iq.From); 
     } 
     catch (Exception ex) 
     { 
      DebugLogger.LogRecord(ex.Message + " [ Function: " + System.Reflection.MethodBase.GetCurrentMethod().Name + " Class: XMPPWrapper ]"); 
     } 

    } 
+1

在行'如果(iq.From!= NULL && ll.Message!= 「」)'還要檢查'LL!= null'。要獲得額外的信用,請查看Caps以查看對方是否實現了這一點。另外,*請*確保你沒有定期輪詢。這會讓你在許多服務器上快速獲得速度限制。 –

1

請確保您閱讀了Wiki,然後查看一些現有代碼中的一些示例。從協議的角度來看,jabber:iq:last應該是微不足道的,但許多客戶端不再實現它。