Indy TIdUDPSever 可以有多个实例链接到同一个 UDP 端口进行监听吗
我有一个 UDP 通信系统,可以在单个端口上广播数据消息。在第二个系统上,我使用 TIdUDPServer 组件捕获这些消息,但该应用程序仅处理消息的子集。
当我开始编写第二个应用程序来处理 UDP 数据广播中的其他消息时,它工作得很好。但是,如果我尝试同时运行两个应用程序,第二个应用程序会引发异常“套接字错误 #10048 地址已在使用中”。
是否可以覆盖/扩展 Indy 以允许两个组件共享相同的 UDP 端口进行监听?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个应用程序在打开各自的套接字时都必须指定
SO_REUSEADDR
标志。 Indy 组件有一个用于此目的的 ReuseSocket 属性。但是,当多个应用程序共享同一端口时,无法控制或保证哪个应用程序将收到哪个消息。他们不会同时收到相同消息的自己的副本。如果您需要这样做,那么您需要第三个应用程序来专门接收所有真实消息,然后根据需要将它们转发到适当的应用程序。否则,请考虑让应用程序以混杂模式侦听 NIC 以接收原始网络数据,而不考虑套接字(但您不能使用 Indy)。Both applications have to specify the
SO_REUSEADDR
flag when opening their respective sockets. Indy components have aReuseSocket
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).