Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.IO;
  4. using jabber.client;
  5.  
  6. namespace JabbR
  7. {
  8. class MainClass
  9. { public static string username,password,server;
  10. public static string[] beolv;
  11. public static bool beolvasva,verbose;
  12. static string TARGET="bkotsis";
  13. static ManualResetEvent done = new ManualResetEvent(false);
  14. public static void Main (string[] args)
  15. {
  16. try
  17. {
  18. beolv = File.ReadAllLines("JabbR.cfg");
  19.  
  20. }
  21. catch (System.IO.FileNotFoundException)
  22. {
  23. Console.WriteLine("Enter your username");
  24. username=Console.ReadLine().ToString();
  25. Console.WriteLine("Enter your password");
  26. password=Console.ReadLine().ToString();
  27. Console.WriteLine("Enter the server you want to use");
  28. server=Console.ReadLine();
  29. File.WriteAllText("JabbR.cfg",username+'\n'+password+'\n'+server);
  30. beolvasva=true;
  31. }
  32. if(beolvasva==false)
  33. {
  34. username=beolv[0];
  35. password=beolv[1];
  36. server=beolv[2];
  37. }
  38. //Client serialisation and settings
  39. JabberClient client =new JabberClient();
  40. client.User=username;
  41. client.Server=server;
  42. client.Password=password;
  43. client.AutoPresence = false;
  44. client.AutoRoster = false;
  45. client.AutoReconnect = -1;
  46.  
  47. //Event handlers
  48. client.OnError += new bedrock.ExceptionHandler(client_OnError);
  49. client.OnAuthenticate+=new bedrock.ObjectHandler(client_OnAuthenticate);
  50.  
  51. // listen for XMPP wire protocol
  52. if (verbose)
  53. client.OnReadText += new bedrock.TextHandler(client_OnReadText);
  54. client.OnWriteText+=new bedrock.TextHandler(client_OnWriteText);
  55.  
  56.  
  57.  
  58. client.Connect();
  59.  
  60. done.WaitOne();
  61.  
  62. //client.Close();
  63.  
  64. }
  65. static void client_OnWriteText(object sender, string txt)
  66. {
  67. if (txt == " ") return;
  68. Console.WriteLine("SEND: " + txt);
  69. }
  70.  
  71. static void client_OnReadText(object sender, string txt)
  72. {
  73. if (txt == " ") return; // ignore keep-alive spaces
  74. Console.WriteLine("RECV: " + txt);
  75. }
  76.  
  77. static void client_OnAuthenticate(object sender)
  78. {
  79. // Sender is always the JabberClient.
  80. JabberClient client = (JabberClient)sender;
  81. client.Message(TARGET, "this is a test");
  82.  
  83. // Finished sending. Shut down.
  84. done.Set();
  85. }
  86.  
  87. static void client_OnError(object sender, Exception ex)
  88. {
  89. // There was an error!
  90. Console.WriteLine("Error: " + ex.ToString());
  91.  
  92. // Shut down.
  93. done.Set();
  94.  
  95. }
  96. }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement