Question

I'm using the boost::asio library.

I've been trying to run my server on port 80, but can't get it to do so. Below is the culpable line in my code, with outcomes in the comments:

// This runs fine, and the webpage is visible on localhost:8000
tcp::acceptor a(*io_service, tcp::endpoint(tcp::v4(), 8000));

// This throws an error (at this line)
tcp::acceptor a(*io_service, tcp::endpoint(tcp::v4(), 80));

// This runs fine, but the webpage is NOT visible on localhost or localhost:80
tcp::acceptor a(*io_service, tcp::endpoint());

I've noticed that endpoint only accepts four-digit port numbers. Could this have something to do with it?

How can I see my page running on port 80? Thanks!

Was it helpful?

Solution

I am not sure how it works on Windows, but on Unix, including Linux, ports below 1024 can only be bound by privileged processes. Try running it as root. Of course you should give up the permissions (using setuid system call) after opening the port.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top