C#socket net direct broadcast [英] C# socket net directed broadcast
问题描述
我有几个LAN(10.0.0.x)连接到WAN(192.168.1.x)。每个通过一个允许网络驱动广播的路由器。这是为了允许WAN中的设备发现LAN中的设备。
我可以在局域网(10.0.0.255)上发送广播并在我的套接字上接收它。但是当我移动到WAN时,我可以在wireshark中看到它,但不是我的插座。换句话说,我有一个地址10.0.0.1的决定通过网关向192.168.1.255发送相同的消息但我的套接字没有收到它。发生这种情况时,源地址是路由器的地址。这是我的插座的代码:
I have several LANs(10.0.0.x) connected to a WAN(192.168.1.x). Each through a router that allows a network drirected broadcast. This is to allow the devices in the LANs to be discovered by devices on the WAN.
I can send a broadcast on the LAN(10.0.0.255) and receive it on my socket. But when I move to the WAN I can see it in wireshark, but not my socket. I other words I have a decive with address 10.0.0.1 sending the same message to 192.168.1.255 through a gateway but my socket is not receiving it. When this happens the source address is the addres of the router. Here is the code for my socket:
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);
推荐答案
hi,
只是一个想法:
你是否根据你的IP地址激活了端口?
greetz
just an idea:
do you have activated port forwording to your ip-address ?
greetz
这篇关于C#socket net direct broadcast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!