尝试将数据包单播到可用网络时出现问题
尝试将数据包单播到可用网络。 总共有3个网络。 设法仅在一个网络中获取数据包。但我无法在不同网络中接收数据包。
使用这段代码..
foreach (var i in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
{
foreach (var ua in i.GetIPProperties().UnicastAddresses)
{
System.Windows.Forms.MessageBox.Show(ua.Address.ToString());
IPAddress Tip = IPAddress.Parse(ua.Address.ToString());
IPEndPoint targetEndPoint = new IPEndPoint(Tip, iTargetPort);
MyUdpClient sendUdpClient = new MyUdpClient();
int numBytesSent = sendUdpClient.Send(CombineHeaderBody, CombineHeaderBody.Length, targetEndPoint);
}
}
有什么问题? 谢谢。
Trying to unicast packets to available networks. There are totally 3 networks. Managed to get packets in only one network.But i am not able to receive the packets in different networks.
using this code..
foreach (var i in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
{
foreach (var ua in i.GetIPProperties().UnicastAddresses)
{
System.Windows.Forms.MessageBox.Show(ua.Address.ToString());
IPAddress Tip = IPAddress.Parse(ua.Address.ToString());
IPEndPoint targetEndPoint = new IPEndPoint(Tip, iTargetPort);
MyUdpClient sendUdpClient = new MyUdpClient();
int numBytesSent = sendUdpClient.Send(CombineHeaderBody, CombineHeaderBody.Length, targetEndPoint);
}
}
What is the prob ? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您正在尝试向自己发送数据包?
您确定没有混淆单播和多播地址吗?
好吧,所以你不是在尝试多播...
你的每个网络接口都有一个 IP 地址。 您在这里所做的是将数据包发送到您的网卡。 这实际上并不是网络问题,因为您的计算机很可能知道自己的 IP 地址并将其重新路由到 127.0.0.1
I think that you're trying to send packets to yourself?
Are you sure you're not confusing unicast and multicast addresses?
Ok so you're not trying to multicast...
Each of your network interface has an ip address. What you're doing here is sending a packet to your network card. It is not really a matter of network because your machine most probably knows its own ip addresses and reroute it to 127.0.0.1
由于您有多个接口,因此您是多宿主的。 对于每个接口,您都会有一个 IP 地址。 因此,通过三个接口,您将拥有三个本地 IP。 当您使用 UdpClient 时,您需要使用其 IP 指定要发送的接口。
假设您有以下三个本地 IP
,并且您想要将 UDP 数据包发送到 10.2.5.5,您需要将其发送到 10.2.0.1,因此使用以下代码
并将 UDP 数据包发送到 10.1.90.5,您需要将其发送到 10.1 .0.1所以使用下面的代码
两者的区别是localEndPoint和targetEndPoint。
Since you have more than one interface you are multihomed. For each interface you will have an IPaddress. So with three interfaces you will have three local IP's. When you use the UdpClient you need to specify which interface to send out by using it's IP.
lets assume you have the following three local IP's
and you want to send a UDP packet to 10.2.5.5 you need to send it out 10.2.0.1 so use the following code
and to send a UDP packet to 10.1.90.5 you need to send it out 10.1.0.1 so use the following code
The difference between the two are the localEndPoint and the targetEndPoint.
我不是一个网络专家,但我会尝试尝试一下。 我假设所有数据包都是通过默认接口发送的,该接口知道三个地址:它自己的地址、环回地址和网关地址。 因此,从 192.168.1.111 发往 10.10.1.117 的数据包需要通过默认网关(假设这是 192.168.1.1),但如果 192.168.1.1 不知道到 10.10.0.0 的路由,那么目标主机会怎样?无法访问对吗? 我不知道,这是我的猜测。
虽然,也许我错了。 也许它不使用默认设备,而是使用所有可用的接口以及 TCP/IP 堆栈。 不管怎样,我很想看看你发现了什么。 请随时通知我们最新情况。
此外,记下地址可能会有所帮助。 追踪路线是你的朋友。
I'm not much of a network guru, but I'll try to take a stab at it. I assume that all the packets are sent through the default interface which knows of three adresses: it's own, loopback, and gateway. Therefore a packet from 192.168.1.111 destined for 10.10.1.117 would need to pass through the default gateway (let's just say this is 192.168.1.1), but what if 192.168.1.1 does not know the route to 10.10.0.0, then destination host unreachable right? I don't know, that's my guess.
Although, maybe I'm wrong. Maybe it doesn't use a default device and instead uses all available interfaces along with the TCP/IP stack. Anyway, I'm curious to see what you find though. Please keep us updated.
Additionally, noting down the addresses might be helpful. Trace route is your friend.