Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UDP Broadcast across VLANs
#1
Hi,
I have a server app that needs to know if there are other instances of the same server app running on the same VLAN or different VLANs.

When I try using the Broadcast function in the UDP client/server and using the IP address "255.255.255.255," it only sends the message to the current VLAN and local machine. But when I use that VLAN IP address something like "192.168.5.255" it does broadcast the message to all the servers that listen to the port I defined. 

I already have a way in mind which is to force the user to add a list of VLANs in a config file, but let's say they forget or make a mistake I want this to be more automatic so that the Master server can discover the other VLANs on the network on its own. Also, I don't want to loop all possible IP numbers from 0 to 255 just to discover if there is a possibility that this IP is in fact a VLAN or not.

Does Indy have anything to help me with this, or maybe broadcast the message to the whole network across VLANs?
Reply
#2
(12-05-2024, 09:21 AM)Ahmed Sayed Wrote: When I try using the Broadcast function in the UDP client/server and using the IP address "255.255.255.255," it only sends the message to the current VLAN and local machine.

Makes sense, as broadcasts are not supposed to cross VLAN/subnet boundaries.

(12-05-2024, 09:21 AM)Ahmed Sayed Wrote: But when I use that VLAN IP address something like "192.168.5.255" it does broadcast the message to all the servers that listen to the port I defined. 

Yes, when you want to broadcast to a specific VLAN/subnet, you have to use that VLAN/subnet's particular broadcast IP. Otherwise, don't use a broadcast at all, use unicast or multicast instead.

(12-05-2024, 09:21 AM)Ahmed Sayed Wrote: Does Indy have anything to help me with this

Not for the specific issue of broadcasting across VLANs, no. It does have multicast components, though.

(12-05-2024, 09:21 AM)Ahmed Sayed Wrote: or maybe broadcast the message to the whole network across VLANs?

Not by default, no. You would need extra help from your network hardware to forward broadcasts from one VLAN/subnet to another. You can't control that from your program code.

Reply
#3
Ok, I noticed now that there is a TIdIPMCastServer/Client components, I never used them before how can I use them to fit my needs?
Reply
#4
(12-05-2024, 05:51 PM)Ahmed Sayed Wrote: I noticed now that there is a TIdIPMCastServer/Client components, I never used them before how can I use them to fit my needs?

I'm not overly familiar with multicast, either. But I think it would go like this...

You would have your app use TIdIPMCastClient to subscribe to a multicast group and listen for incoming packets on a given port.

Then, when you want to discover other running instances, you can use TIdIPMCastServer to send your query packet to the multicast group IP on that port. Each TIdIPMCastClient.OnIPMCastRead handler can then send a reply back to the sender IP/Port as you were probably doing before.

The catch is that TIdIPMCastServer and TIdMCastClient are primarily designed for a producer/consumer model, respectively. As such, TIdIPMCastServer does not have any reading methods of its own (but its Binding does), so I'm not sure if you can easily receive all of the replies with TIdIPMCastServer. You might need to use TIdUDPServer instead. You should be able to send out your query packet to the multicast group IP using either TIdUDPServer or TIdIPMCastServer. At least TIdUDPServer has an OnUDPRead event.

Reply
#5
Well, If I am going to use the UDP server anyway, I guess using it the way I mentioned is better for me now. Also, I am not a networking guru, but I think that we might need to configure something in each router and switch in order for multicasting to work in the first place.

Thanks
Reply
#6
(12-06-2024, 08:43 AM)Ahmed Sayed Wrote: Well, If I am going to use the UDP server anyway, I guess using it the way I mentioned is better for me now.

Multicast can cross VLAN boundaries, UDP broadcast doesn't.

Also, keep in mind that broadcasting simply doesn't exist in IPv6, so you will likely have to deal with multicasting eventually.

(12-06-2024, 08:43 AM)Ahmed Sayed Wrote: Also, I am not a networking guru, but I think that we might need to configure something in each router and switch in order for multicasting to work in the first place.

Perhaps. At least to let multicast traffic cross VLANs/subnets. But you have to configure them to setup your VLANs anyway...

Reply
#7
But I don't understand the IP in multicast group property in both component client/server, for example my IP at home in the local network is: 192.168.1.x why does the multi cast IP starts with 224? I can't even get it to work on the same vlan network between my machine and a VM both on the same network, like PC1: 192.168.1.10 PC2: 192.168.1.20 what is the proper IP to use in multi cast group in order to make send data?
Reply
#8
(12-07-2024, 02:56 AM)Ahmed Sayed Wrote: why does the multi cast IP starts with 224?

In IPv4, all multicast addresses begin with the first 4 bits set to 1110, thus making the first octet be in the range of 224 (11100000) .. 239 (11101111).

Reply
#9
Yes but when I use the same IP on both sides client and server nothing is being sent. Am I missing something?
Reply
#10
(12-07-2024, 11:42 AM)Ahmed Sayed Wrote: Yes but when I use the same IP on both sides client and server nothing is being sent. Am I missing something?

I can't answer that without knowing your actual network config and socket setup. But in general, the receiver needs to bind to a local IP/port interface for listening, and then subscribe to the multicast group IP using that interface. Then the sender can send UDP packets to the group IP.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)