如何在boost :: asio服务器中使用端口80?

时间:2014-04-29 16:29:54

标签: c++ http boost port boost-asio

我正在使用boost::asio库。

我一直在尝试在端口80上运行我的服务器,但无法让它这样做。下面是我的代码中的罪魁祸首,在评论中有结果:

// 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());

我注意到端点只接受四位数的端口号。这可能与它有关吗?

如何在端口80上看到我的页面正在运行?谢谢!

1 个答案:

答案 0 :(得分:6)

我不确定它在Windows上是如何工作的,但在Unix(包括Linux)上,1024以下的端口只能受特权进程的约束。尝试将其作为root运行。当然,您应该在打开端口后放弃权限(使用setuid系统调用)。

相关问题