boost:asio IPv4 address and UDP comms

自闭症网瘾萝莉.ら 提交于 2019-12-05 03:57:27

The problem you are currently seeing appears to be your usage of this line:

targetIP.from_string("10.1.1.75", myError); 

boost::asio::ip::address::from_string is a static function, that returns a constructed ip::address object. Change it to look like this:

targetIP = boost::asio::ip::address::from_string("10.1.1.75", myError); 

And your IP address should be populated properly.

On the top of my head, you try to bind the socket to an endpoint with address 10.1.1.75, but that seems to be a remote endpoint? I would assume you would like to bind it locally and use send_to, as it is UDP

Giorgos Dimitriadis

In this line there is an error:

targetIP = boost::asio::ip::address::from_string("10.1.1.75", myError);

You should put:

targetIP = boost::asio::ip::address_v4::from_string("10.1.1.75", myError);

and then targetIP has the right value!

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