Advertisement
Ladislav

Problem with agsXMPP

Nov 3rd, 2011
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Security;
  6. using System.Security.Cryptography.X509Certificates;
  7. using agsXMPP;
  8. using agsXMPP.protocol.client;
  9.  
  10. namespace XMPPTest
  11. {
  12.     class Program
  13.     {
  14.         private static XmppClientConnection conn;
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             conn = new XmppClientConnection("jabber.cz");
  19.             conn.UseStartTLS = true;
  20.             conn.Username = "user";
  21.             conn.Password = "password";
  22.             conn.Resource = "test";
  23.             conn.Priority = 5;
  24.             conn.OnAuthError += new XmppElementHandler(conn_OnAuthError);
  25.             conn.OnLogin += new ObjectHandler(conn_OnLogin);
  26.             conn.OnError += new ErrorHandler(conn_OnError);
  27.             conn.ClientSocket.OnValidateCertificate += new RemoteCertificateValidationCallback(ClientSocket_OnValidateCertificate);
  28.  
  29.             conn.Open();
  30.  
  31.             bool term = false;
  32.             while (!term)
  33.             {
  34.                 char c = (char)Console.Read();
  35.                 switch (c)
  36.                 {
  37.                     case 'q':
  38.                     case 'Q':
  39.                         term = true;
  40.                         break;
  41.  
  42.                     case 'm':
  43.                     case 'M':
  44.                         conn.Send(new Message("anotheruser@jabbim.cz", "hello"));
  45.                         break;
  46.                 }
  47.             }
  48.  
  49.             conn.Close();
  50.         }
  51.  
  52.         static void conn_OnAuthError(object sender, agsXMPP.Xml.Dom.Element e)
  53.         {
  54.             Console.WriteLine("OnAuthError()");
  55.         }
  56.  
  57.         static bool ClientSocket_OnValidateCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  58.         {
  59.             X509Certificate2 cert2 = certificate as X509Certificate2;
  60.             if (cert2 != null)
  61.             {
  62.                 bool valid = cert2.Verify();
  63.                 return valid;
  64.             }
  65.             else
  66.                 return false;
  67. }
  68.  
  69.         static void conn_OnError(object sender, Exception ex)
  70.         {
  71.             Console.WriteLine(ex.ToString());
  72.         }
  73.  
  74.         static void conn_OnLogin(object sender)
  75.         {
  76.             Console.WriteLine("OnLogin()");
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement