I'm in the process of writing a turn-based card game in Java but need some advice on making it multiplayer. Players can create a multiplayer game and then others can join that game, taking turns to play their move. I've spent hours looking into all the different ways to implement this but could really do with some help. I'll list the requirements and what I've found out so far:
- It is an entirely Java game so using something like RMI is not an issue for that reason
- Player makes a move, this move is sent to the server, the server sends this move to the other players (clients) in the game.
- The server needs to store all the games in progress and the players in them (currently doing this with a
HashMap<UniqueGameID, GameObject>.
I've been experimenting with sockets and RMI so far and it seems:
RMI:
+ Handles multithreading and access to the hashmap
- Either have to poll the server to see if a player has moved or use callbacks which don't work through firewalls
Sockets:
+ Allows for asynchronous callbacks(?)
- Can't easily access hashmap from the multiple threads that are spawned(?)
- More complicated than RMI
I've also been looking into JMS, JINI/JavaSpaces, JGroups and anything else that I can find but I have no idea which one will work best. I've got the client->server part of RMI up and running but server->client seems out of the question as polling is so inefficient and unscalable
I'd really appreciate any advice you have.
Many thanks
EDIT: I have since discovered ConcurrentHashMap which I think solves one of my problems.