Advertisement
farum12

[RR] Server II

Apr 28th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Net;
  4. using System.Net.Sockets;
  5. using System.Text;
  6.  
  7. namespace Server
  8. {
  9.     public class UDPListener
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             UdpClient udpServer = new UdpClient(11000);
  14.             Console.WriteLine("MAIN SERVER");
  15.             while (true)
  16.             {
  17.                 var remoteEP = new IPEndPoint(IPAddress.Any, 11000);
  18.                 byte[] recivedData = udpServer.Receive(ref remoteEP); // listen on port 11000
  19.                 Console.WriteLine("Received data from:\t" + remoteEP.ToString() + " Data: " + Encoding.Default.GetString(recivedData));
  20.                 byte[] check = Encoding.ASCII.GetBytes("testConnection:ANSWERPLZ");
  21.  
  22.  
  23.                 if (((IStructuralEquatable)recivedData).Equals(check, StructuralComparisons.StructuralEqualityComparer))
  24.                 {
  25.                     byte[] sentData = Encoding.ASCII.GetBytes("I'm replying!");
  26.                     udpServer.Send(sentData, sentData.Length, remoteEP); // reply back
  27.                     Console.WriteLine("Sent data to:\t\t" + remoteEP.ToString() + " Data: " + Encoding.Default.GetString(sentData));
  28.                 }
  29.                
  30.  
  31.  
  32.                
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement