Receiving multicast data from different groups on the same socket in linux

99封情书 提交于 2019-12-05 18:44:10
user207421

No, you can't bind a socket to 2 ports, you need a socket per port.

In TCP, there needs to be one socket per client. This is because the socket needs to have a connection "accepted." This is done by calling accept on the server's listening socket, and it returns a new socket (with a new port) that denotes that specific client-server connection.

In UDP, there is no "connection," but rather, you just send data to a socket and hope it gets there (it might not). If you use a UDP socket, all your clients can send data to it, and your server won't have to call accept on incoming connections. You will have to create your own protocol to identify the clients sending the messages (inside hte message that is, you'll have to parse it to see if its client 1 or client2).

Let me know if this is unclear.

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