How to receive UDP packets from any ip and any port?(如何从任何 ip 和任何端口接收 UDP 数据包?)
问题描述
我想使用 C# 的 UdpClient 来监听任何传入的 UDP 数据包.我想从任何 IP 和任何端口接收数据包.
I wanted to use C#'s UdpClient to listen to any incomming UDP packets. I want to receive packets from any IP and any port.
我尝试了以下方法:
UdpClient udpClient = new UdpClient(0);
IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);
byte[] data = udpClient.Receive(ref ep);
但没有成功.
有谁知道怎么回事?提前致谢!
Does anyone know whats wrong? Thanks in advance!
推荐答案
RECEIVE on any port?这太疯狂了.你会被来自其他应用程序的消息淹没(尝试 TcpView 了解一下每秒在您的系统上传递多少条消息!)
RECEIVE on any port? That's insane. You would be flooded with messages from other applications (try TcpView for an idea of how many messages get passed on your system per second!)
您必须指定一个端口!端口有点像一个标识符——这个数据包是为这个程序准备的(由端口号标识)
You must specify a port! Port is sort of like an identifier -- this packet is meant for THIS program (identified by port #)
Send 在任何端口上都是明智的,因为它要求系统为您选择一个端口发送 OUT 端口——这对于您的应用程序来说并不像发送方有时那么重要
Send on any port is sensible, as it asks the system to choose a port send OUT port for you -- which isn't really that important to your application as the sender sometimes
这篇关于如何从任何 ip 和任何端口接收 UDP 数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从任何 ip 和任何端口接收 UDP 数据包?


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01