Multi-user game client-server architecture RMI / JMS / Sockets

I am writing a turn-based card game in Java, but I need to be advised to make it multi-player. Players can create a multiplayer game, and then others can join this game, take turns to play their turn. I spent hours studying all the ways to implement this, but I really could handle it with some help. I have listed the requirements and what I have discovered so far:

  • This is a fully Java game, so using something like RMI is not a problem for this reason.
  • The player makes a move, this move is sent to the server, the server sends this move to other players (clients) in the game.
  • The server needs to save all games and players in them (currently this is done with HashMap<UniqueGameID, GameObject>.

I have experimented with sockets and RMI so far, and it seems:

Rmi

+ Handles multithreading and hashmap access

- Either you need to poll the server to see if the player has moved or is using callbacks that do not work through firewalls.

Sockets

+ Allows asynchronous callbacks (?)

- It is not easy to access hashmap from multiple threads that are spawned (?)

- More complex than RMI

I also studied JMS, JINI / JavaSpaces, JGroups and everything else I can find, but I have no idea which one will work best. I have a client-> server-side RMI and it works, but server-> client seems like the question is impossible, because the polling is so inefficient and inaccessible

, .

EDIT: ConcurrentHashMap, , , .

+3
3

ZeroMQ. , , . RMI Sockets.

+2

Second Life , :

(Second Life Wiki)

+1

Hazelcast? . , .

■ java.util. {, Set, List, Map} ■ java.util.concurrency.locks.Lock ■ java.util.concurrent.ExecutorService

■ MultiMap ■ / ■ ■ J2EE JCA

■ ■ ■ Java ■ HTTP

■ Support for cluster and membership information ■ Dynamic discovery ■ Dynamic scaling ■ Dynamic partitioning with backups ■ Dynamic failure ■ Web cluster monitoring tool

0
source

Source: https://habr.com/ru/post/1775936/


All Articles