如何从任何 ip 和任何端口接收 UDP 数据包? [英] How to receive UDP packets from any ip and any port?

查看:19
本文介绍了如何从任何 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 数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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