Reputation: 5508
I have a sockets program that requires port 1002 to be open and I wanna know how to port forward in C++ on windows so i may use this port freely?
Upvotes: 2
Views: 7726
Reputation: 24328
I believe the most popular approach is to write documentation that tells the user what port(s) to open on their firewall.
Upvotes: 0
Reputation: 11421
Starting with Windows XP, Microsoft offers a UPnP library. 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. 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.
Upvotes: 1
Reputation: 34602
So, you need UPnP or 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.
There is no guarantee that will work, so you may need to go further and use STUN, TURN or 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. Encourage users to install v6 and Teredo.
Upvotes: 4
Reputation: 5330
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.
Upvotes: 8
Reputation: 70523
You can't port forward in a programming language, that is something that is set up on the router.
Upvotes: -1