4
\$\begingroup\$

I'm working on a Networked multiplayer game, but while developing and for testing I want to set up a local server that acts like the multiplayer server.

My thought is to approach the server as a proxy setup. Creating a class that the client sees and essentially allowing it to either load the server code in itself or to use a networking layer.

Is this a good approach? Are there other approaches to look into? What pitfalls should I be watching for?

Update

A bit more specifically I need to do this because I am targeting the Ouya and I can't guarantee a network connection, or even a spare machine to run the server on. And inside Android it is more difficult to setup and launch a service rather than include my server code right into a client build.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

In my experience, I would suggest you start with a networking layer, right out of the gate. Connecting to a network (and the issues related to it) are worth confronting head on. Since it's a multiplayer game, you're going to want to start facing those issues early (and often).

Further, my recommendation would be to develop your server code, run it locally, and when you're ready, move it to its real location. In other words, rather than think of the server as merely a temporary solution for testing, think of it as the ultimate solution in a temporary location, otherwise you're going to be developing the server code twice.1 If you're running your server on the same computer as your emulator, you can just connect to localhost. Even better is to connect to your IP address (the external one, seen from outside your network), and then set up port forwarding of whatever ports your game communicates over to send the packets to your server computer. With that setup you can still test with a reasonable number of people without raising the ire of your ISP.

As far as where the codebase "lives," my suggestion would be: do NOT include the server code in your client codebase. Advantages include:

  • It keeps the client smaller. (Which is good, since users don't like bigger downloads)

  • It keeps the server code away from those who would decompile the client to hack your game.

Nonetheless, there will likely be a need for some classes to be shared between the client and server. That's why I recommend that you DO include the client code in your server codebase. Classes that are common to both the client and server can live on the client side. (Alternatively, you could have three codebases: (1) server; (2) client; and (3) shared, but I don't think that's necessary, since the server having extra code it doesn't need from the client isn't a big deal.)

1For my project, I used KryoNet and can't recommend it enough. It's a very simple, clean, open source client-server solution, written in java.

\$\endgroup\$
5
  • \$\begingroup\$ I'm actually already setup quite like you suggest. 3 Code bases, networking already works. My problem is I'm targeting the Ouya and I can't guarantee a network connection while I'm developing, and it's much more difficult to try to start the server as a secondary Android application. \$\endgroup\$
    – CLo
    Mar 3, 2013 at 1:41
  • \$\begingroup\$ How about running the server on the computer that you're developing on? Awesome that you're targeting Ouya, by the way. \$\endgroup\$ Mar 3, 2013 at 1:47
  • \$\begingroup\$ I develop in several places, one of them being the college. And there especially I can't control the network. Also, I'd like to be able to demo the game with less hardware and hopefully less chances of something going wrong. I've been working on this the past few hours and will be testing later tonight or tomorrow. so far, it's literally an interface and a class and it looks like it should do what I need. \$\endgroup\$
    – CLo
    Mar 3, 2013 at 1:51
  • \$\begingroup\$ Additionally, I haven't been able to connect my dev kit to any unsecured wireless networks. The kind you'd find at a lot of hotels / conference centers / colleges, that require you to connect to the web and fill out information. \$\endgroup\$
    – CLo
    Mar 3, 2013 at 1:52
  • \$\begingroup\$ Sounds like you've worked out something that suits your development needs. \$\endgroup\$ Mar 3, 2013 at 2:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .