I created a multicast sender and receiver, where the sender sends messages to 239.255.0.1:54321. It works well.
The receiver’s steps are as follows:
- Create a socket
- Bind to 239.255.0.1:54321
- Join the multicast group 239.255.0.1
- Use recvfrom to receive messages
My question is, in a cross-machine communication scenario, how can the sender ensure that the receivers have not occupied port 54321?
I do not want the sender and receiver to both statically configure port 54321; I want this port to be dynamically discovered by the receiver through a service discovery mechanism.
Port 54321 is randomly chosen by sender. After that the Service Discovery tells the receiver multicast dest ip:port. In such a case, the multicast receiver may not be able to bind to port 54321 because another program may have already occupied this port.
Is there any way to avoid binding to the multicast_port on the reader side?
I tried connect(), bind() and join_multicast_group, changing their orders, but It seems no work.
Changkun is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3