[英]How to make UdpClient.Receive to listen to specific network interface?
On my machine i have 3 network adapter. 在我的机器上,我有3个网络适配器。
I need to listen to specific network adapter on my application. 我需要在应用程序上收听特定的网络适配器。
I scan all the network adapter (using NetworkInterface.GetAllNetworkInterfaces Method () ) on my machine and i hold now all the network adapter that are type of Ethernet. 我扫描了机器上的所有网络适配器(使用NetworkInterface.GetAllNetworkInterfaces方法()),现在保存了所有以太网类型的网络适配器。
And i need to bind my UdpClient to one of them ( and listen to him ) 而且我需要将UdpClient绑定到其中之一(并听他讲)
How do i do it ? 我该怎么做 ?
That binds UdpClient
to specific network interface. UdpClient
绑定到特定的网络接口。
var portNum = 2000; // your port
var ipAddress = IPAddress.Parse("192.168.0.1"); // your IP
var listenEndpoint = new IPEndPoint(ipAddress, portNum);
var myClient = new UdpClient(listenEndpoint);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.