Tom*_*ove 5 c# udp network-programming
I'm currently developing a network application on my machine with 2 network interfaces with the following setup -

I want to send UDP message by using the first configuration with IP 192.168.1.2.
using (var udpClient = new UdpClient(5556))
{
udpClient.Connect(IPAddress.Parse("192.168.1.2"), 5556);
// DO STUFF
}
Run Code Online (Sandbox Code Playgroud)
When I try this I get the following error -
No connection could be made because the target machine actively refused it
奇怪的是,当我禁用我的其他网络,这是完美的,但有2个连接(局域网和WiFi)它不再工作...我猜它是发送错误的适配器?这是因为我的默认网关是相同的还是我做错了什么?我是开发基于网络的应用程序的新手......
您必须指定一个IPEndPoint网卡 IP,如下所示:
var endpoint = new IPEndPoint(IPAddress.Parse("192.168.1.2"), portNum);
UdpClient client = new UdpClient(endpoint);
Run Code Online (Sandbox Code Playgroud)