C # UDP multicast transmission and reception

'''cs
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace Client
{
class Program
{
static void Main(string[] args)
{
UdpClient client = new UdpClient();
client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));
IPEndPoint multicast = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 37020);
string mess = " 0414E4C1-1B08-408F-9442-BC2B6834D29D inquiry ";
byte[] buf = Encoding.Default.GetBytes(mess);
Thread t = new Thread(new ThreadStart(RecvThread));
t.IsBackground = true;
t.Start();
while (true)
{
client.Send(buf, buf.Length, multicast);
Thread.Sleep(1000);
}
}

    static void RecvThread()
    {
        UdpClient client = new UdpClient(37020);
        client.JoinMulticastGroup(IPAddress.Parse("239.255.255.250"));
        IPEndPoint multicast = new IPEndPoint(IPAddress.Parse("239.255.255.250"),0);
        while (true)
        {
            byte[] buf = client.Receive(ref multicast);
            string msg = Encoding.Default.GetString(buf);
            Console.WriteLine(msg);
            Console.WriteLine(multicast);
       }
   }

}
}
'''

Guess you like

Origin www.cnblogs.com/luchi88/p/10948781.html