Вопрос

I'm using the below code in my application to bind an IP endpoint to a socket, I have a quick question is "7777" setting the port of the local endpoint? If so then how can I automatically generate a port instead of having to set it myself.

sockconn.lowest_layer().bind(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("192.168.1.1"), 7777));
Это было полезно?

Решение

Bind to 0. A port will be chosen for you.

sockconn.lowest_layer().bind(boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("192.168.1.1"), 0));
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top