nateshoffner

Untitled

Sep 29th, 2011
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. public static bool Echo(string ip)
  2. {
  3.     var udpClient = new UdpClient { Client = { ReceiveTimeout = 1000, SendTimeout = 1000 } };
  4.     var localpt = new IPEndPoint(IPAddress.Parse(ip), 32887);
  5.     var datagram = Encoding.ASCII.GetBytes("HELLO");
  6.  
  7.     try
  8.     {
  9.         udpClient.Send(datagram, datagram.Length, localpt);
  10.         return Encoding.ASCII.GetString(udpClient.Receive(ref localpt)) == "HI";
  11.     }
  12.  
  13.     catch
  14.     {
  15.         return false;
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment