Sign in to follow this  
domok

Connection with Port forwarding

Recommended Posts

Hello

I want to connect to a server behind NAT. So I've forwarded a port on the server and I can access it, but of course only if I know it's external IP. Of course I can look it up here [url="http://www.whatismyip.com/"]http://www.whatismyip.com/[/url] but I want that you don't have to look it up somewhere. The server should find out his own external IP and thats my problem: how can you do that??? After that the IP is uploaded to an ftp server and the rest is easy.

So how can you find out the IP of the router / external IP??

Or would you approach this problem differently? Is this the normal way to connect with port forwarding??

Share this post


Link to post
Share on other sites
You can use UPnP to communicate between your app and IGDs (Internet Gateway Devices) on your network. If your router has UPnP turned on, your software can ask it what your external IP is, and also make port forwarding requests.

UPnP involves sending a UDP packet to your IGD to discover its "service URL" (this is usually done either by UDP broadcasting or by using your network configuration's 'gateway' address). After you have the service URL, you send some HTTP+XML requests to the router to request the external IP and/or forward ports.

It's kind of a pain. Most of the UPnP libraries I've used make certain assumptions about a network that aren't always true (such as 'only one router' and 'the local computer hopefully doesn't have Internet Connection Sharing enabled'). Also, some routers don't properly implement UPnP and will break certain library implementations.

Share this post


Link to post
Share on other sites
Click on the "[size="3"][color="#0000ff"]Networking and Multiplayer FAQ[/color][/size]" link at the top of the forum.

Scroll down to FAQ#9. Read after "There's a number of documents describing how to..." and follow the links. The links are not underlined on my system, so I had to hover over them to find them.

Share this post


Link to post
Share on other sites
[quote name='domok' timestamp='1307726030' post='4821764']
I know that NAT punch-through would be best but I'll start with UPnP that's enough for the moment

[/quote]


UPnP is terrible, for several reasons. I generally recommend everyone to turn it off.

First, it is a security problem -- if you have a firewall to keep bad guys in check, but then open up a mechanism for bad buys to punch holes in your firewall, then what good is it?

Second, it's a clunky technical design. For example, what if you have two clients on the inside that both want to control the firewall in the same way? Much better to either require manual configuration (where the user is in control), or to use automatic punch-through, where it "Just works" (at the cost of needing an external matchmaker).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this