【发布时间】:2013-07-29 19:18:24
【问题描述】:
我有几个 LAN (10.0.0.x) 连接到 WAN (192.168.1.x)。每个都通过一个允许网络定向广播的路由器。这是为了让 WAN 上的设备能够发现 LAN 中的设备。
我可以在 LAN(10.0.0.255) 上发送广播并在我的套接字上接收它。但是当我移动到广域网时,我可以在wireshark中看到它,但不是我的套接字。换句话说,我有一个地址为 10.0.0.1 的设备通过网关向 192.168.1.255 发送相同的消息,但我的套接字没有接收到它。当这种情况发生时,源地址是路由器的地址。这是我的套接字的代码:
udpSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
//Assign the any IP of the machine and listen on port number 5000
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 5000);
//Bind this address to the server
udpSocket.Bind(ipEndPoint);
IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 5000);
//The epSender identifies the incoming clients
EndPoint epSender = (EndPoint)ipeSender;
//Start receiving data
udpSocket.BeginReceiveFrom(byteData, 0, byteData.Length,
SocketFlags.None, ref epSender, new AsyncCallback(ReceiveAnnounce), epSender);
我对每条消息都有一个wireshark 跟踪,但我不确定发布它的最佳方式。谢谢。
【问题讨论】:
标签: c# sockets networking udp wireshark