Question

I am making a multiplayer game. Now I am trying to choose the technology to connect the android devices to the server. The clients run on Android, and the game is MMORPG. I would like to write the server in java. Right now I have only 3 ideas for it:

1) creating multithreading environment with plain java and sockets. In this way it will be easier to perform full-duplex connection between the game client and the server. But I have the following concerns:

1.1) The game is MMORPG with a large number of objects, and I am not sure how such solutions are scaled if there are for example 5000 people playing at the same time. How many threads will I be able to run on java Machine? How can I approximately calculate that? In case 1 thread is reading for each socket and 1 thread is writing to the socket (so 2 threads for 1 player).

1.2) When the number of players grows, how will I be able to scale my self-written jar-archive to distribute over several servers? Maybe there is some special trick to do that?

1.3) A lot of programming overhead - sockets API is quite low level.

2) Creating a Servlet-interface for serving HTTP requests.

2.1) Easy to control sessions (and authorization) as long as each player has his/her own session.

2.2) can connect to java EE EJB or whatever - a lot of complications with system-level programming are taken away. So I can concentrate on writing business logic.

2.3) Can serve all types of clients with HTTP - mobile devices + browsers.

2.4) High-speed - even 1 servlet container can serve a few thousand requests per second so it will be really fast.

2.4) But this approach cant provide a full-duplex communication. I will have to send requests every 1 second to check for updates. 1 second delay does not make a lot of difference for the game as it is turn-based, but still it generates a lot of traffic. Is it feasible when there are many players playing? I heard about some COMET technology, but it seems like if the server has to push many messages in row, I will still have to send requests every time + this technology is not well established yet.

3) Creating sockets and connecting them through JMS to the java EE server.

3.1) Cool because allows for full duplex communication between clients and server + provides all cool features of java EE. Later can be extended to browser through servlet interface.

3.2) It seems like some kind of overengineering. Is it really how people would do that? I mean is it even the correct way? Would any sane developer do it like that?

I would like you to help me out with the choice please. I dont have much experience with doing some work like that. And would like to stick to the best practices.

Was it helpful?

Solution

Why Rewrite What you can Get Off the Shelf?

Why not use RedDwarf Server (formerly Project DarkStar)?

RedDwarf Server is an open source middleware solution for developing the server-side of massively multiplayer online games. It is the official community fork of Project Darkstar, an open source project supported and managed by Sun Microsystems. - from RedDwarf's Wikipedia article

RedDwarf's domain seems down today (2013-06-12), but there's still a wiki, and they are migrating to a GitHub repo.

RedDward presents its philosophy and goals as:

  • Make server-side game code reliable, scalable, persistent, and fault-tolerant in a manner that is transparent to the game developer.
  • Present a simple single-threaded event-driven programming model to the developer. The developer should never have his or her code fail due to interactions between code handling different events. (from the RedDwarf Tutorial)

Not that this doesn't mean that server-code is single-threaded, but that it is abstracted from the game developer's perspective. The RedDwarf Tutorial provides a lot more information on what RedDwarf can do and clarifies many of its design decisions.

One point of concern for you, though, was that the multi-node capability wasn't fully implemented last time I check (ca. 2011).

From Scratch

That shouldn't stop you from attempting to do most of these things from scratch, if you value the learning experience. However, this is a major effort and will be rather time-consuming, and as, you noted in your question, some of these issues are rather low-level in the tech stack to deal with and will greatly increase the complexity of the code you'll have to maintain.

But anyways, regarding your 3 options, your first one seems the best to me, if you were to go for a home-made implementation. Option 2 (using HTTP servlets) seems only adapted for some games, though I guess it could be a relatively decent alternative to implement something yourself while still delegating to the a middleware, and you could benefit from many web server additions for handling the load (cache modules, etc...). Option 3 (using JMS + JEE) indeed seems overengineered, but it's hard to know for sure without knowing what you have in mind.

And if you're here to try to learn, then obviously Option 1 will cover a lot of ground. But it's going to be a rather uphill battle.

OTHER TIPS

1.1) you can't think in term of one Thread by user. Depending of machine configuration but you could load thousands of threads but it will not scale and lose a lot of time in Thread context switch. Better think NIO Netty like framework with few incoming and outcoming Thread pool executor that perform incoming messages under milli second execution.

1.2) You can simply scale by putting in front of you game server a loadbalancer component that can forward incoming player to right server according their load

1.3) NIO can handle thousands to to millions connection on a single box. Don't worry with this.

2.1) Manage your player sessions and 2.2) be away of EJB architecture. It will eat all your box power instead of allocating power to your game which is your goal.

2.3) HTTP can serve all clients but if you run realtime game i encourage to use binary socket and keep HTTP only for loadbalancing , login , stats and fallback when can't establish a socket connection.

2.4) Socket based server can handle hundred thousands incoming message per second. This is the property of low latency system

While it's very interesting to dive in building such system. What is your goal? Learn to build such system or succeed your game?

Many java multiplayer game server technology framework already exist. SmartFox Server, ElectroTank...

We have our own java high load Nuggeta multiplayer crossplatform java game server that addresses all points discussed above and much more. If you wanna try it it's free.

If your goal is to write a game server it's awesome venture that can takes long time but very exciting. If your goal is to succeed your game. Pick up among Java game server SDK already existing.

Licensed under: CC-BY-SA with attribution
scroll top