Search code examples
delphiindy

Can the Indy TIdUDPSever have multiple instances linked to the same UDP Port for listening


I have a UDP communication system that broadcasts data messages on a single port. On a second system, I capture these messages with a TIdUDPServer component, but this application only processes a subset of the messages.

When I started writing a second application to process other messages in the UDP data broadcast, it works just fine. But if I try to run both applications at the same time, the second application raises the exception 'Socket Error #10048 Address already in use.'

Is it possible to override/extend the Indy to allow two components to share the same UDP port for listening?


Solution

  • Both applications have to specify the SO_REUSEADDR flag when opening their respective sockets. Indy components have a ReuseSocket property for that purpose. However, when multiple apps are sharing the same port, there is no way to control or guarantee which app will receive which message. They will NOT both receive their own copies of the same messages. If you need to do that, then you need a third app that receives all of the real messages exclusively and then forwards them to the appropriate app as needed. Otherwise, consider having the apps listen to the NIC(s) in promiscuous mode to receive the raw network data without regard to sockets (you can't use Indy for that, though).