Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- namespace Server
- {
- public class UDPListener
- {
- static void Main(string[] args)
- {
- UdpClient udpServer = new UdpClient(11000);
- Console.WriteLine("MAIN SERVER");
- while (true)
- {
- var remoteEP = new IPEndPoint(IPAddress.Any, 11000);
- byte[] recivedData = udpServer.Receive(ref remoteEP); // listen on port 11000
- Console.WriteLine("Received data from:\t" + remoteEP.ToString() + " Data: " + Encoding.Default.GetString(recivedData));
- byte[] check = Encoding.ASCII.GetBytes("testConnection:ANSWERPLZ");
- if (((IStructuralEquatable)recivedData).Equals(check, StructuralComparisons.StructuralEqualityComparer))
- {
- byte[] sentData = Encoding.ASCII.GetBytes("I'm replying!");
- udpServer.Send(sentData, sentData.Length, remoteEP); // reply back
- Console.WriteLine("Sent data to:\t\t" + remoteEP.ToString() + " Data: " + Encoding.Default.GetString(sentData));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement