سؤال

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