How can two processes which bind on the same port receive the same message?

1.7k views Asked by At

I have two processes. both listen to the same port.
This is UDP multicast so both use the socket option SO_REUSEADDR, and join the multicast group prior to bind().

When I send a message to the multicast group ip:port only one of the processes gets the message.
How can both of them get it?

Thanks.

2

There are 2 answers

0
Raspbeguy On

I don't think it's possible, and I think that sometimes it is a lot more coherent this way. Maybe you should implement a receiver (which will listen to the port) which will distribute the messages to the other processes via inter-processes communication (pipes for instance).

0
AMS On

Two process can listen at the same port. Although two sockets for connections can't be bound to the same IP address with same port.

You just add an entry for each process in your hosts file that points to a unique ip address.

Something like : You bind process P1 to 127.0.0.1 port 8080 and P2 to 127.0.0.2 port 8080.