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)
).