C#实现UDP组播
来源:互联网 发布:linux exec函数 编辑:程序博客网 时间:2024/04/28 21:16
[csharp] view plain copyprint?
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- namespace Test
- {
- class Program
- {
- static void Main(string[] args)
- {
- UdpClient client = new UdpClient(5566);
- client.JoinMulticastGroup(IPAddress.Parse("234.5.6.7"));
- IPEndPoint multicast = new IPEndPoint(IPAddress.Parse("234.5.6.7"), 7788);
- byte[] buf = Encoding.Default.GetBytes("Hello from multicast");
- 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(7788);
- client.JoinMulticastGroup(IPAddress.Parse("234.5.6.7"));
- IPEndPoint multicast = new IPEndPoint(IPAddress.Parse("234.5.6.7"), 5566);
- while (true)
- {
- byte[] buf = client.Receive(ref multicast);
- string msg = Encoding.Default.GetString(buf);
- Console.WriteLine(msg);
- }
- }
- }
- }
组播地址为 224.0.0.0 ~ 239.255.255.255,其中 224.0.0.0~224.255.255.255 不建议在用户程序中使用,因为它们一般都有特殊用途。
0 0
- C#实现UDP组播
- C#实现UDP组播
- C#实现UDP组播
- C#实现UDP单播
- UDP实现组播
- UDP组播实现
- UDP组播通信实现
- UDP组播的实现
- Java UDP 组播实现
- ios 接收 c# socket udp 组播
- C#编写UDP组播上位机
- JAVA实现UDP组播聊天程序
- java UDP协议和组播实现
- java UDP协议和组播实现
- [疯狂Java]UDP:MulticastSocket实现组播
- UDP的组播简单实现
- STM32F103ZET6+ENC28J60+LWIP实现UDP组播
- Linux UDP 单播 组播 广播实现
- gSoap的“error LNK2001: 无法解析的外部符号 _namespaces”解决方法
- x4412编译内核(ubuntu)
- [Intent] 调用其他应用 setComponent
- php配置
- 第九周 项目2 对称矩阵压缩存储的实现与应用(1)
- C#实现UDP组播
- Java Web Start 开发向导
- 答题吧远程代答
- 设计模式之Builder模式
- mysql 存储过程
- JavaScript的arguments 对象使用总结
- 江湖英雄X隐私政策
- weui框架代码汇总
- java的动态代理机制详解