Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5.  
  6. //Creates a UdpClient for reading incoming data.
  7. UdpClient udpServer = new UdpClient(9999);
  8.  
  9. //Creates an IPEndPoint to record the IP Address and port number of the sender.
  10. //IPAddress ip = IPAddress.Any;
  11. //udpServer.EnableBroadcast = true;
  12. IPAddress ip = IPAddress.Parse("192.168.3.64");
  13. IPEndPoint RemoteIpEndPoint = new IPEndPoint(ip, 9999);
  14.  
  15.  
  16. try
  17. {
  18. // Blocks until a message is received on this socket from a remote host (a client).
  19. /*C*//*onsole.WriteLine("Server is blocked");*/
  20. int tal = 0;
  21. while (true)
  22. {
  23. //Byte[] receiveBytes = udpServer.Receive(ref RemoteIpEndPoint);
  24. //Server is now activated");
  25.  
  26. //string receivedData = Encoding.ASCII.GetString(receiveBytes);
  27. //string[] data = receivedData.Split(' ');
  28. //string clientName = data[0];
  29. //string text = data[1] + data[2];
  30.  
  31. //Console.WriteLine(receivedData);
  32. ////Console.WriteLine("Received from: " + clientName.ToString() + " " + text.ToString());
  33.  
  34. //string sendData = "Server: " + text.ToUpper();
  35. /*B*//*yte[] sendBytes = Encoding.ASCII.GetBytes(tal);*/
  36. Byte[] sendBytes = Encoding.ASCII.GetBytes("Number is: " + tal);
  37. udpServer.Send(sendBytes, sendBytes.Length, RemoteIpEndPoint);
  38. Console.WriteLine(tal.ToString());
  39. tal++;
  40. Thread.Sleep(1000);
  41. //Console.WriteLine("This message was sent from " +
  42. // RemoteIpEndPoint.Address.ToString() +
  43. // " on their port number " +
  44. // RemoteIpEndPoint.Port.ToString());
  45. }
  46. }
  47. catch (Exception e)
  48. {
  49. Console.WriteLine(e.ToString());
  50. }
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement