Код: Выделить всё
using System.Net.Sockets;
using System.Net;
using System.Text;
int PORT = 6122;
UdpClient listener = new UdpClient(PORT);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, PORT);
try
{
while (true)
{
Console.WriteLine("Waiting for broadcast");
byte[] bytes = listener.Receive(ref groupEP);
Console.WriteLine($"Received broadcast from {groupEP} :");
Console.WriteLine($" {Encoding.ASCII.GetString(bytes, 0, bytes.Length)}");
}
}
catch (SocketException e)
{
Console.WriteLine(e);
}
finally
{
listener.Close();
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... ram-packet