2015-01-14 88 views
1

我嘗試連接到服務器時遇到了一個問題。 我正在使用庫agsXMPP和下一個代碼。當我試圖連接到服務器時,我不能。我無法登錄服務器。我也嘗試給一些用戶發送消息。使用agsxmpp登錄到XMPP

 agsXMPP.XmppClientConnection xmpp = new XmppClientConnection(); 
     string server = "ipServer"; 

     string user = "user"; 
     string pass = "password"; 
     int port = 5222; 
     bool _wait = true; 

     xmpp.Status = "available"; 
     xmpp.Show = ShowType.chat; 
     xmpp.Priority = 1; 
     xmpp.SendMyPresence(); 
     xmpp.Server = server; 
     xmpp.Port = port; 
     xmpp.Username = usuCon; 
     xmpp.Password = usuCon; 

     xmpp.Open(); 

     agsXMPP.Jid JID = new Jid("[email protected]); 
     agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message(); 
     msg.Type = agsXMPP.protocol.client.MessageType.chat; 
     msg.To = JID; 
     msg.Body = "hi how are you? message" + DateTime.Now.ToString(); 



     xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); }; 
     agsXMPP.protocol.server.Presence presencia2 = new agsXMPP.protocol.server.Presence(); 
     presencia2.Type = new PresenceType(); 
     xmpp.OnLogin += xmpp_OnLogin; 

     Console.WriteLine("Wait"); 
     int i = 0; 
     do 
     { 
      Console.Write("."); 
      i++; 
      if (i == 10) 
       _wait = false; 
      Thread.Sleep(1000); 
     } while (_wait); 


     Console.WriteLine("\n" + msg); 
     Console.Read(); 
    } 

    private void xmpp_OnLogin(object sender) 
    { 
     Console.WriteLine("yes"); 
    } 
+0

,你能否告訴我們的錯誤? –

+0

我沒有錯誤。問題是,當我試圖做xmpp.open()不這樣做。我可以使用xmpp_OnLogin方法進行驗證。我debbug我的項目和xmpp_OnLogin永遠不會被調試。 –

+0

應該禁用IPv6。按照這裏的說明:http://www.techunboxed.com/2014/10/how-to-disable-ipv6-in-windows-10.html – Najeeb

回答

0

我有這個問題,我這段代碼解決了這個問題:

 XmppClientConnection xmpp = new XmppClientConnection(); 
     xmpp.ConnectServer = "ipServer"; 
     xmpp.Server = "domain name"; 
     xmpp.Port = 5222; 
     xmpp.Username = "my userName"; 
     xmpp.Password = "my password"; 
     xmpp.Open(); 

xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);