Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1.                 case "check":
  2.                     if (parameters.Length > 1)
  3.                     {
  4.                         String s = "Server is ";
  5.  
  6.                         IPHostEntry entry = Dns.GetHostEntry(parameters[0]);
  7.  
  8.  
  9.                         AutoResetEvent connectDone = new AutoResetEvent(false);
  10.  
  11.                         TcpClient c = new TcpClient();
  12.  
  13.                         c.BeginConnect(
  14.                             entry.AddressList[0], int.Parse(parameters[1]),
  15.                             new AsyncCallback(
  16.                                 delegate(IAsyncResult ar)
  17.                                 {
  18.                                     try
  19.                                     {
  20.                                         c.EndConnect(ar);
  21.                                         connectDone.Set();
  22.                                     }
  23.                                     catch (Exception e)
  24.                                     {
  25.                                         client.LocalUser.SendMessage(target.Name, "Exception: " + e.Message);
  26.                                     }
  27.                                 }
  28.                             ), c
  29.                         );
  30.  
  31.                         if (!connectDone.WaitOne(2000))
  32.                         {
  33.                             c.Close();
  34.                             s += "down";
  35.                         }
  36.                         else
  37.                         {
  38.                             c.Close();
  39.                             s += "up";
  40.                         }
  41.  
  42.  
  43.  
  44.                         client.LocalUser.SendMessage(target, s);
  45.                     }
  46.                     break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement