Listening to a UDP broadcast

房东的猫 提交于 2019-12-06 16:53:11

You don't bind to the broacast address; you bind to the machine's local IP (or 0.0.0.0 for all of them). The broadcasts will reach the socket all the same. That's why it's a broadcast. The logic of "this packet is sent to a broadcast address, means we wanna receive it" happens on the TCP/IP stack level.

Don't bind to 127.0.0.1.

To get the sender's address, use recvfrom() and note the penultimate parameter.

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