开发者

Getting the broadcast source ip address with boost::asio

开发者 https://www.devze.com 2023-02-09 14:55 出处:网络
I\'m currently struggling with a basic socket problem using boost::asio. A server is sending broadcasts in my LAN to discover client machines. The broadcast is successfully read on the client, but now

I'm currently struggling with a basic socket problem using boost::asio. A server is sending broadcasts in my LAN to discover client machines. The broadcast is successfully read on the client, but now I'm stuck with the question of how to get the IP address of the server, to be able to establish a regular connection to it.

I tried to query the remote endpoint开发者_StackOverflow after receiving the broadcast, but of course I get 0.0.0.0 as a result. Same for querying the local endpoint before sending the broadcast on the server (I'd send the server IP in the broadcast, then)

So, what is the default procedure to get the broadcast sender address?

Thanks :)


try using the recieve_from or async_recieve_from methods for the UDP socket... they take an endpoint parameter that is filled in when the data is recieved.

0

精彩评论

暂无评论...
验证码 换一张
取 消