tags:

views:

407

answers:

2

Hello.

I made a remote engine for a game which must be able to works in P2P.

It perfectly works in LAN, but there's a problem when computers are behind router(s) and want to communicate through internet.

Is there any solution to this, which doesn't need to manipulate the router configuration? Because since most of my gamers may not be very acknowledged in informatic, I'd like to solve this problem as easily as possible, without any intervention from them.

Thanks,

KiTe.

+4  A: 

You need the client behind the router to initiate an OUTGOING connection. Once that's established you can have 2 way communication on it. This is why most P2P games have some sort of server to set up matches between clients. You can have each client establish a socket to the server and then connect them to each other.

There was an alternative called 'NAT hole punching' a while back, but I'm not sure how reliable that was.

This is what separates LogMeIn from VNC.

LoveMeSomeCode
hmm if I make one client connect to a website through a php API, get its public IP adress and bind the socket to it, will it works? (suposing that the other can also get this, no matter the manner)
KiTe
no, unfortunately the public ip isnt enough. like remus said, evryone nowadays has a NAT enabled router. That router will assign a private IP address to the in house machine, and every request that leaves the building gets an entry in the NAT table that ties the loca IP/Port pair to a public IP/Port pair. This is what configuring the router does, it maps any incoming request on a specific port to a particular computer in the house. External computers have no way of knowing your internal IP.(which is good)
LoveMeSomeCode
+1  A: 

These days almost all home users are behind a form of NAT, macking it impossible in practice to set up real peer-to-peer communication as the application listenning port is unreachable from the net.

In theory there is UPnP which allows applications( running under elevated priviledges) to enable port forwarding dynamically on the home router (via Internet Gateway Device Protocol), but in practice this is so unreliable that I haven't seen any real use of it.

The most reliable solution is to have a central hub (your game server) that forwards packets between clients that initiate the connection from behind the NAT device. But that is a serious cost to you, as you'll need to cash out the cost of provisioning and operating this hubs which can be serious money, even with dynamic just-in-time solutions like EC2.

Update

Perhaps you can use the Codeplex UPnP NAT traveral project.

Remus Rusanu