简体   繁体   English

如何在C ++中向前移植?

[英]How to port forward in C++?

我有一个套接字程序需要打开端口1002,我想知道如何在Windows上的C ++中向前移植,以便我可以自由使用此端口?

Port forwarding is done upstream of the client system, typically on the router. 端口转发是在客户端系统上游(通常在路由器上)完成的。

I believe some applications use Universal Plug and Play to communicate with the upstream router to open a port publicly but you'll have to do a lot of research to see how it's done: I haven't the slightest. 我相信有些应用程序使用通用即插即用功能与上游路由器进行通信,以公开打开端口,但是您必须做大量研究才能看到它是如何完成的:我没有丝毫意见。

So, you need UPnP or NAT-PMP. 因此,您需要UPnP或NAT-PMP。 Your system may have libraries for doing those protocols, or you can use muniupnp , which has both a server to run on a Linux or BSD box to test against, and a client library. 您的系统可能具有执行这些协议的库,或者您可以使用muniupnp ,该服务器具有要在Linux或BSD上运行以进行测试的服务器和客户端库。

There is no guarantee that will work, so you may need to go further and use STUN, TURN or ICE. 无法保证会奏效,因此您可能需要走得更远并使用STUN,TURN或ICE。 There's a library for doing those things here . 有做这些事情一个图书馆在这里

And always remember, sometimes it's just impossible. 永远记住,有时候这是不可能的。 Implement IPv6 as well, sometimes that works when IPv4 doesn't. 也可以实施IPv6,有时在IPv4无效时也可以使用。 Encourage users to install v6 and Teredo. 鼓励用户安装v6和Teredo。

Starting with Windows XP, Microsoft offers a UPnP library . 从Windows XP开始,Microsoft提供了UPnP库 It's actually fairly complicated to use as the library just offers the basics of communicating with network devices. 使用该库实际上相当复杂,因为该库仅提供与网络设备进行通信的基础。 You will have to study the various UPnP specifications in order to perform device-specific tasks such as port forwarding. 您将必须研究各种UPnP规范才能执行特定于设备的任务,例如端口转发。 Believe me, this is a lot of hard work to do to accomplish relatively little; 相信我,要完成相对较少的工作要做很多艰巨的工作。 better to just put it in your documentation somewhere that the user might have to consult their router manual in order to forward the necessary ports. 最好只是将其放在文档中,用户可能必须查阅其路由器手册才能转发必要的端口。 This is what almost everybody does. 几乎每个人都这样做。

我相信最流行的方法是编写文档,告诉用户在防火墙上打开哪个端口。

您不能使用编程语言进行转发,这是在路由器上设置的。

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

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