我正在连接到发送 UDP 数据包的系统,作为响应(发送到特定 IP 地址)和广播(根据 WireShark,dest 为 255.255.255.255)
我可以正确接收“直接”数据包,但我不知道如何获取广播数据包。我假设我需要第二个具有不同绑定的 TIdUDPClient,但我无法让它工作。
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();
然后我有其他几乎相同的线程调用reader/broadcastReader->ReceiveBuffer()
. 一个reader
工作正常,但broadcastReader->receiveBuffer()
永远不会回来......
为 C++ 代码和 Delphi 标签道歉 ;-)