Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive broadcast packets with Indy10 TIdUDPClient?

I'm connecting to a system that sends UDP packets, both as responses (sent to a specific IP address) and as broadcasts (dest 255.255.255.255, according to WireShark)

I can receive the 'direct' packets correctly, but I can't work out how to get the broadcast ones. I assume I need a second TIdUDPClient with different bindings, but I haven't been able to get it working.

TIdUDPClient *reader(new TIdUDPClient(NULL));
TIdUDPClient *broadcastReader(new TIdUDPClient(NULL));

reader->Port = 2000;
reader->Host = "192.168.0.1";
reader->Connect();

broadcastReader->Port = 2000;
// broadcastReader->Host = "0.0.0.0"; // This doesn't work, but is here as an example
broadcastReader->BroadcastEnabled = true;
broadcastReader->Connect();

I then have other near-identical threads calling reader/broadcastReader->ReceiveBuffer(). The reader one works fine, but broadcastReader->receiveBuffer() never returns...

Apologies for C++ code and a Delphi tag ;-)

like image 661
Roddy Avatar asked Jan 20 '26 02:01

Roddy


1 Answers

TIdUDPClient is not designed for receiving broadcasts. Use TIdUDPServer instead.

like image 154
Remy Lebeau Avatar answered Jan 21 '26 20:01

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!