1

I am in the process of developing a game for an assignment, and would love some pointers on how to design the server-client interaction. Ideally, I'd love to be able to have multiple instances of clients up, that communicate with the some main server.

More specifically, I was thinking of setting up this main server as the backend of my game, which would be played through a web browser, and it would serve the game logic to clients. Each of the clients would be an instance of some Game class that would make the necessary initializations and continue to be the entry point through which that particular client accesses the game logic available on the logic server.

Does this design make sense, and seem viable as a way of implementing a game like this?

Also, does using threads make sense for this (as in, each Game instance would be a new thread on the server)?

sahil
  • 309
  • 2
  • 9
  • I recommend looking into [non-blocking socket channels](http://stackoverflow.com/questions/24616774/non-socket-based-java-server/24617983#24617983) – Vince Mar 21 '16 at 05:26

1 Answers1

1

Yes, having a separate thread for each client does make sense.

have a look at Similar Question MultiClient server - Java

and following answer https://stackoverflow.com/a/23042582/5828425 ... this will give you idea on how to implement multiclient chat application. now you can send and receive the data using similar api to send chat and receive chat messages. instead of chat messages you can send and receive the game data updates and state transfers.

Community
  • 1
  • 1
  • 2
    Although 1:1 thread:client ratio works, it's not scalable, and he should look into non-blocking alternatives using the NIO API (or third-party libs such as Apache Mina or JBoss Netty) – Vince Mar 21 '16 at 05:23
  • yes, I agree, for highly scaleable systems this approach might take too many resources in terms of memory and computing resources – meet thakkar Mar 21 '16 at 16:36
  • 1
    Sorry for the late acceptance, but I've made a lot of headway from this answer. Currently, I'm using a thread for each client, as this is a school project, but will definitely mention the consideration of technologies such as Mina for scalability. Thanks! – sahil Apr 07 '16 at 04:37