Is it okay to multicast data from different processes to the same host and port?

三世轮回 提交于 2019-12-25 05:32:45

问题


I have multiple processes sending different types of messages to the same ip and port so that when I write the client I would only need one reader thread rather than multiple reader threads. Have I embarked on a design pattern or is my strategy ill advised? Obviously, I could send to different ip:port but that would mean multiple threads on my client. Any thoughts?


回答1:


You send multicast data to a group and port, not to "host". Listening processes would have to join that group, and sending process will have to enable IP_MULTICAST_LOOP socket option. Take a look at this Multicast over TCP/IP HOWTO.

Disclaimer: I don't know for sure, but I believe that the meaning of that socket option is reversed on Windows, so if you are that unlucky - check the MSDN or something.

Edit 0:

It's totally OK for multiple processes to send data to the same UDP port since granularity on the receiver side is one datagram per read, and you know where each datagram was sent from (see recvfrom(2)).



来源:https://stackoverflow.com/questions/6470140/is-it-okay-to-multicast-data-from-different-processes-to-the-same-host-and-port

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!