views:

506

answers:

6

I'm making a network game (1v1) where in-game its p2p - no need for a game server.

However, for players to be able to "find each other", without the need to coordinate in another medium and enter IP addresses (similar to the modem days of network games), I need to have a coordination/matching server.

I can't use regular web hosting because:

  • The clients will communicate in UDP.
  • Therefore I'll need to do UDP Hole Punching to be able to go through the NAT
  • That would require the server to talk in UDP and know the client's IP and port
  • afaik with regular web hosting (php/etc) I can only get the client's IP address and can only communicate in TCP (HTTP).

Options I am currently considering:

  • Use a hosting solution where my program can accept UDP connection. (any recommendations?)

  • UDPonNAT seems to do this but uses GTalk and requires each client to have a GTalk account for this (which probably makes it an unsuitable solution)

Any ideas? Thanks :)

+3  A: 

I don't see any other choice than to have a dedicated server running your code. The other solutions you propose are, shall we say, less than optimal.

If you start small, virtual hosting will be fine. Costs are pretty minimal.

tomfanning
There are other choices, but all of them are more work than it's worth. When it comes to netcode, it's best to keep things simple.
Sneakyness
+2  A: 

Rather than a full-blown dedicated server, you could just get a cheap shared hosting service and have the application interface with a PHP page, which in turn interfaces with a MySQL database backend.

For example, Lunarpages has a $3/month starter package that includes 5gb of space and 50gb of bandwidth. For something this simple, that's all you should need.

Then you just have your application poll the web page for the list of games, and submit a POST request in order to add their own game to the list.

Of course, this method requires learning PHP and MySQL if you don't already know them. And if you do it right, you can have the PHP page enter a sort of infinite loop to keep the connection open and just feed updates to the client, rather than polling the page every few seconds and wasting a lot of bandwidth. That's way outside the scope of this answer though.

Oh, and if you're looking for something absolutely free, search for a free PHP host. Those exist too! Even with an ad-supported host, your app could just grab the page and ignore the ads when you parse the list of games. I know that T35 used to be one of my favorites because their free plan doesn't track space or bandwidth (it limits the per-file size, to eliminate their service being used as a media share, but it shouldn't be a problem for PHP files). But of course, I think in the long run you'll be better off going with a paid host.

Edit: T35 also says "Free hosting allows 1 domain to be hosted, while paid offers unlimited domain hosting." So you can even just pay for a domain name and link it to them! I think in the short term, that's your best (cheapest) bet. Of course, this is all assuming you either know or are willing to learn PHP in order to make this happen. :)

Ricket
@Ricket: thanks for the suggestion. I now found out that php hosting won't work for me because afaik it won't allow me to communicate with the clients in UDP
yairchu
Right. I just went back and re-figured-out the concept of NAT traversal, and then realized that yes you will need UDP capabilities. Though, for negotiating the list of games and such, you should use TCP. You only need the server to receive the UDP packets to determine the clients' outgoing ports, and then you can send a message to them over TCP telling each of the other's outgoing UDP port. But hopefully you know all this already. If you need a refresher, the Security Now podcast is an awesome resource: http://www.grc.com/securitynow.htm#42
Ricket
And just FYI, PHP is technically capable of socket transmissions; but it would not be useful in this case, because of the nature of PHP and its 30-second execution limit. You can perhaps consider Google App Engine? I think Python would be a great language to write this in, however much I normally despise it.
Ricket
@Ricket: why do you normally despise Python?
yairchu
A: 

An intermediate solution between hosting your own dedicated server and a strictly P2P networking environment is the gnutella model. In that model, there are superpeers that act like local servers, having known IP addresses and being connected to (and thus having knowledge of) more clients than a typical peer. This still requires you to run at least one superpeer yourself, but it gives you the option to let other people run their own superpeers.

Eric
@Eric: I think in gnutella the server might be doing a lot more work (search shared files etc) and for my problem this model might be overkill.
yairchu
You're right that it is doing a lot more work. I was merely suggesting the model where P2P clients form a network where they are aware of more peers than just the ones that they are directly connected to. This is the gnutella model.
Eric
+2  A: 

First, let me say that this is well out of my realm of expertise, but I found myself very interested, so I've been doing some searching and reading.

It seems that the most commonly prescribed solution for UDP NAT traversal is to use a STUN server. I did some quick searches to see if there are any companies that will just straight-up provide you with a STUN hosting solution, but if there even were any, they were buried in piles of ads for simple web hosting.

Fortunately, it seems there are several STUN servers that are already up and running and free for public use. There is a list of public STUN servers at voip-info.org.

In addition, there is plenty more information to be had if you explore SO questions tagged "nat".

Joel Wietelmann
@Joel Wietelmann: I'm going to try this. I'll let you know if it works out! Thanks :)
yairchu
+1  A: 

There's nothing that every net connection will support. STUN is probably good, UPnP can work for this.

However, it's rumored that most firewalls can be enticed to pass almost anything through UDP port 53 (DNS). You might have to argue with the OS about your access to that port though.

Also, check out SIP, it's another protocol designed for this sort of thing. With the popularity of VOIP, there may be decent built-in support for this in more firewalls.

If you're really committed to UDP, you might also consider tunneling it over HTTP.

Marsh Ray
+1  A: 

how about you break the problem into two parts - make a game matcher client (that is distinct from the game), which can communicate via http to your cheap/shared webhost. All gamers who wants to use the game matching function use this. THe game matcher client then launches the actual game with the correct parameters (IP, etc etc) after obtaining the info from your server.

The game will then use the standard way to UDP punch thru NAT, etc etc, as per your network code. The game dont actually need to know anything about the matcher client or matcher server - in the true sense of p2p (like torrents, once you can obtain your peer's IPs, you can even disconnect from the tracker).

That way, your problems become smaller.

Chii