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

How to use port 80 in a boost::asio server?

本文关键字:服务器 boost asio      更新时间:2023-10-16

我正在使用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上运行的页面?谢谢

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