0

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?

jimbouki
  • 1
  • 1
  • 1
    Threads in general have nothing to do with IPs and ports, and vise versa. You don't need threads to read from multiple sockets. What is your particular problem? Try rephrasing the question. – Nikolai Fetissov Jun 24 '11 at 15:38
  • I will ultimately write an app that needs to read the data. A listener to each ip:port tuple creates an individual thread for blocking IO. My question is still, Is it okay to multicast data from different processes to the same host:port tuple. – jimbouki Jun 24 '11 at 15:56

1 Answers1

2

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

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
  • Group or host what I meant was IP address. I am still wondering whether multiple proceses should send data to that same ip:port? I already know about loopback and the other stuff you mention. Just need answer to main question. – jimbouki Jun 24 '11 at 16:22
  • 1
    Thanks that makes sense. At this point I have the following options: – jimbouki Jun 24 '11 at 17:22
  • Thanks that makes sense. At this point I have the following options: 1) Multiple senders same ip:port, Client reader blocking IO on one thread; 2) Multiple senders to their own ip:host, Client reader blocking IO on multiple threads; 3) Multiple senders to their own ip:host, Client uses async IO. I imagine the amount of data and the number of threads would weigh on this decision – jimbouki Jun 24 '11 at 17:30