Network Broadcasting. How?
-
Hi all, I have a question on how to properly implement network broadcasts. Our network is divided in subnets and I need help (it is probably more of a networking question than code) To broadcast I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 8300); UpdClient client = new UdpClient(); client.Send(...,ep); To receive I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0); UpdClient client = new UdpClient(8300); byte [] buffer = client.Receive(ref ep); My machine is on the 192.168.1.xxx subnet and all machines on the 1.xxx network receive the broadcast, but machines on the 192.168.8.xxx network do not. What IP address should I use in the sending portion to make sure I broadcast to the 8.xxx network?
-
Hi all, I have a question on how to properly implement network broadcasts. Our network is divided in subnets and I need help (it is probably more of a networking question than code) To broadcast I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 8300); UpdClient client = new UdpClient(); client.Send(...,ep); To receive I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0); UpdClient client = new UdpClient(8300); byte [] buffer = client.Receive(ref ep); My machine is on the 192.168.1.xxx subnet and all machines on the 1.xxx network receive the broadcast, but machines on the 192.168.8.xxx network do not. What IP address should I use in the sending portion to make sure I broadcast to the 8.xxx network?
OK, this is how subnetting works: An IP-Address is 32 Bit long. The first part determines the Network, the second part identifies the Host. Your network class is C, which means: the first 24 Bit are Network, the last 8 Bit are host. Subnet-Mask is 255.255.255.0 (which means exactly the same: all bits set to 1 are part of the Network-ID, the bits set to 0 are part of the Host-ID. There never are any 0s between 1s, so its always ...11111000... and NEVER ...110110000... etc.) What is that subnet-mask good for, if the network-class already contains the necessary information? That is VERY simple: Using an IP-Address from ANY Network and the corresponding subnet mask, you can easily derive the broadcast-address of that network. Your code doesnt work cause IPAddress.Broadcast is 255.255.255.255 (which means "EVERY ADDRESS ON ALL NETWORKS" and is probably filtered by your L3-switches or routers). Try the following: If you need to contact all hosts in the 192.168.8.0 Network, use a bitwise-or of one host-address (e.g. 192.168.8.4) and the inverted subnet-mask (e.g. 0.0.0.255). That will return the broadcast-address of the network (in this case, 192.168.8.255). If you need to calculate the Network-Address, use a bitwise-and instead and dont invert the subnet-mask. Remember the following: The first address in a subnet always is the Network Address, the last address always is the Broadcast. If you are not using CIDR, the following is true: Subnetmask for Class-A Networks: 255.0.0.0 Subnetmask for Class-B Networks: 255.255.0.0 Subnetmask for Class-C Networks: 255.255.255.0 Cheers Sid
-
Hi all, I have a question on how to properly implement network broadcasts. Our network is divided in subnets and I need help (it is probably more of a networking question than code) To broadcast I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 8300); UpdClient client = new UdpClient(); client.Send(...,ep); To receive I use this code: IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0); UpdClient client = new UdpClient(8300); byte [] buffer = client.Receive(ref ep); My machine is on the 192.168.1.xxx subnet and all machines on the 1.xxx network receive the broadcast, but machines on the 192.168.8.xxx network do not. What IP address should I use in the sending portion to make sure I broadcast to the 8.xxx network?
AFAIK UDP multicast doesnt work over network boundries, IOW routers. You would have to implement some kind of proxy on the router to re-multicast to the other network segment. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots