简体   繁体   English

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

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

I'm using the boost::asio library. 我正在使用boost :: asio库。

I've been trying to run my server on port 80, but can't get it to do so. 我一直在尝试在端口80上运行服务器,但无法运行它。 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? 如何查看我的页面在端口80上运行? Thanks! 谢谢!

I am not sure how it works on Windows, but on Unix, including Linux, ports below 1024 can only be bound by privileged processes. 我不确定它在Windows上如何工作,但是在Unix(包括Linux)上,低于1024的端口只能由特权进程绑定。 Try running it as root . 尝试以root身份运行它。 Of course you should give up the permissions (using setuid system call) after opening the port. 当然,打开端口后,您应该放弃权限(使用setuid系统调用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM