Reputation: 89
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));
Upvotes: 2
Views: 1068
Reputation: 83255
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));
Upvotes: 3