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

查看:584
本文介绍了如何从任何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!

推荐答案

在任何端口上接收?太疯狂了您将被来自其他应用程序的消息淹没(尝试 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!)

您必须指定端口!端口有点像标识符-此数据包用于THIS程序(由端口号标识)

You must specify a port! Port is sort of like an identifier -- this packet is meant for THIS program (identified by port #)

发送是明智的,因为它要求系统为您选择一个端口发送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天全站免登陆