接收广播数据包的C#套接字 [英] C# Socket that receives broadcast packets

查看:514
本文介绍了接收广播数据包的C#套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个套接字并将其绑定到单播地址.但是,它读取发送到广播地址的数据包,我不明白为什么.

I create a socket and bind it to a unicast address. However, it reads packets sent to the broadcast address and I do not understand why.

IPAddress ip;
IPAddress.TryParse("X.X.X.99", out ip);

Socket receiver = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
receiver.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
receiver.Bind(new IPEndPoint(ip, 9999));

byte rcvBuffer = new byte[1500];
int bytesRead = receiver.Receive(rcvBuffer);



使用此代码,我收到的地址同时指向"x.x.x.255:9999"和"x.x.x.99:9999"的数据包,却不明白为什么.有人知道为什么吗?



With this code I receive packets addressed to both "x.x.x.255:9999" and "x.x.x.99:9999" and do not understand why. Anyone know why?

推荐答案

这是广播,而不是多播. x.x.x.255是广播地址.
This is broadcast, not multicast. the x.x.x.255 is a broadcast address.


这篇关于接收广播数据包的C#套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆