• C#组播消息收发


    发送组播消息:

    static void Main(string[] args)
            {
                UdpClient udpClient = new UdpClient();
                IPEndPoint broadcastIp = new IPEndPoint(IPAddress.Parse("224.0.0.122"), 4533);
                int i = 0;
                while (true)
                {
                    Console.WriteLine(i);
                    byte[] b = Encoding.UTF8.GetBytes("我在组播消息" + i++);
                    udpClient.Send(b, b.Length, broadcastIp);
                    System.Threading.Thread.Sleep(1000);
                }
            }

    接收组播消息:
    static void Main(string[] args)
            {
                UdpClient receiveUdpClient = new UdpClient(4533);
                receiveUdpClient.JoinMulticastGroup(IPAddress.Parse("224.0.0.122"));
                receiveUdpClient.Ttl = 50;
                IPEndPoint remoteIP = new IPEndPoint(IPAddress.Any, 0);
                while (true)
                {
                    byte[] r = receiveUdpClient.Receive(ref remoteIP);
                    Console.WriteLine(Encoding.UTF8.GetString(r));
                }
            }

  • 相关阅读:
    利用Vue这些修饰符帮我节省20%的开发时间
    ELK API
    ssh编译安装
    谷歌浏览器皮肤
    整理了100篇Linux技术精华
    使用Prometheus+Grafana监控MySQL实践
    mysqldiff
    kafka命令
    calico 文件丢失问题
    Prometheus 告警分配到指定接收组
  • 原文地址:https://www.cnblogs.com/langu/p/3125923.html
Copyright © 2020-2023  润新知