Port mapping (with upnp)

Started by
3 comments, last by domok 12 years, 8 months ago
Hello

I'm trying to forward a port with miniupnp but it doesn't work as I want it to.

What I do is:

the one that hosts the session opens a port with a couple of miniupnp functions but the interesting one is the following

UPNP_AddPortMapping( Urls.controlURL, Data.first.servicetype, Port, Port, LanAddr, "desc", "UDP", 0, 0 );

Now as you can see I use the same port for external and internal port but I don't know why there are 2...?
After that I create the server (with RakNet), with again the same Port. Is this correct so far??

No for the client: Does the client only have to connect (with RakNet) with the external ip of the server and again the same port? Or does he also need to open a port or something?

Am I doing something completely wrong??
Some documentation would also be nice to have
Advertisement

Now as you can see I use the same port for external and internal port but I don't know why there are 2...?
After that I create the server (with RakNet), with again the same Port. Is this correct so far??
No for the client: Does the client only have to connect (with RakNet) with the external ip of the server and again the same port? Or does he also need to open a port or something?


First, there needs to be two ports, because you need to specify:
1) Which port should your router open to the external world. Say, port 80 for a web server.
2) Which port should it forward to on the inside. This may be different -- you might be running Apache locally on port 8080.

Second, yes, the server needs to listen to the port that you told the router to forward to (not from).

Third, yes, the client should connect to the external IP and port configured. Note that clients within your local network may not be forwarded, depending on whether your router does "hairpin" NAT or not.

Fourth, UPnP is a broken concept. First, it's a bad idea to give random devices on your network control over how the firewall operates. Second, what if two different machines within the network want to host the same game on the same port? The alternative is to use an introducer/match-maker server on the outside of the NAT, which can also do lobbying and game discovery/server lists. That approach has none of the problems of UPnP, and usually works even if the home router does not support UPnP (some don't support it; some come with it default off; some are intentionally disabled by people who don't want random programs re-configuring their firewall.)
enum Bool { True, False, FileNotFound };
Thanks for the answer!

So I could use a different internal port but I it's not really necessary I mean it also works with the same port right?


Second, yes, the server needs to listen to the port that you told the router to forward to (not from).


I don't really understand that could you explain this?

I know that UPnP isn't really good but for a start I thought it would be enough and a bit easier then having to host a nat punchthrough server. But if you do have good nat punchthrough tutorials that would be great. I only know this one but it hasn't helped me much
NatTraversalArchitecture

So I could use a different internal port but I it's not really necessary I mean it also works with the same port right?

[quote name='hplus0603' timestamp='1314567832' post='4854832']
Second, yes, the server needs to listen to the port that you told the router to forward to (not from).


I don't really understand that could you explain this?

[/quote]

What you need is a good primer on how the Internet Protocol suite works. How does IP work, how does UDP work, how does TCP work, and how are hosts and services addressed on the Internet, and how does routing work.
Without that understanding, it's unlikely that your network code will be robust enough to work on a larger scale.
If you don't want to bother with studying right now, then I suggest you simply manually configure your router's port forwarding or DMZ for now, to make it work for your current case.
enum Bool { True, False, FileNotFound };

What you need is a good primer on how the Internet Protocol suite works. How does IP work, how does UDP work, how does TCP work, and how are hosts and services addressed on the Internet, and how does routing work.
Without that understanding, it's unlikely that your network code will be robust enough to work on a larger scale.
If you don't want to bother with studying right now, then I suggest you simply manually configure your router's port forwarding or DMZ for now, to make it work for your current case.


I totally agree with that but for the moment I just want this uPnP to get working and when the moment comes that I need to implement NAT punchrough and make everything more robust I will look into all this network stuff.
I only need the uPnP for testing but to explain all the people that are testing it for me how to forward a port manually is even more a waste of time than getting the uPnP to work correctly.

So for the server can I just use the same port, than give the testers my external ip and they connect to my computer with the port and ip.
The problem is it sometimes works and sometimes not but the things that happen are so strange (like getting packages back and somethings) that I can't really explain the problems. But they neither occur on the localhost nor when accessing a pc that isn't behind nat...

This topic is closed to new replies.

Advertisement