Search code examples
javapythonoptimizationwebservermultiplayer

Multiplayer card game on server using RPC


Basically I want a Java, Python, or C++ script running on a server, listening for player instances to: join, call, bet, fold, draw cards, etc and also have a timeout for when players leave or get disconnected.

Basically I want each of these actions to be a small request, so that players could either be processes on same machine talking to a game server, or machines across network.

Security of messaging is not an issue, this is for learning/research/fun.

My priorities:

  1. Have a good scheme for detecting when players disconnect, but also be able to account for network latencies, etc before booting/causing to lose hand.
  2. Speed. I'm going to be playing millions of these hands as fast as I can.
  3. Run on a shared server instance (I may have limited access to ports or things that need root)

My questions:

  1. Listen on ports or use sockets or HTTP port 80 apache listening script? (I'm a bit hazy on the differences between these).
  2. Any good frameworks to work off of?
  3. Message types? I'm thinking JSON or Protocol Buffers.
  4. How to make it FAST?

Thanks guys - just looking for some pointers and suggestions. I think it is a cool problem with a lot of neat things to learn doing it.


Solution

  • As far as frameworks goes, Ginkgo looks promising for building a network service (which is what you're doing). The Python is very straightforward, and the asynchronicity enabled by gevent lets you do asynchronous things without generally having to worry about callbacks. The gevent core also gives you access to a lot of building blocks.

    Rather than having lots of services communicating over ports, you might look into either 1) a good message queue, like RabbitMQ or 0mq, or 2) a distributed coordination server, like Zookeeper.

    That being said, what you aim to do is difficult, especially if you're not familiar with the basics. It's a worthwhile endeavor to learn about those basics.

    Don't worry about speed at first. Get it working, then make it scale. Of course, there are directions you can go that will make it easier to scale in the future. Zookeeper in particular gives you easy-to-implement primitives for scaling horizontally (i.e. multiple workers sharing the load). In particular, see the Zookeeper recipe book and their corresponding python implementations (courtesy of the kazoo, a gevent-based client library).

    Don't forget that "fast" also means optimizing your own development time, for quicker iterations and less time cursing your development environment. So use Python, which will let you get up and running quickly now, and optimize later if you really truly start to bind on CPU time or memory use. (With this particular application, you're far more likely to bind on network IO.)