Tips for writing a Client-Server based game

I am thinking of writing a server-based game, and several client programs are connecting to it. The game (very) basically consists of a list of elements that the user can โ€œacceptโ€, which will remove it from the list on all connected computers (this needs to be updated very quickly).

I am thinking about using a Java applet for the client, as I would like it to be portable and run from a browser (mainly on Windows), and also be updated quickly, as well as on a C ++ or Java server running on Linux ( currently only a home server, but perhaps to upgrade to VPS).

The previous โ€œincarnationโ€ of this game was running in the browser and used PHP + mySQL for the backend, but it slowed down the server a bit when several people connected (it was about 8 people, in the end it had to handle a lot more).
Most likely, users will be in the same physical location (with the same public IP address), and the system will receive several requests per second, all of which will require sending the list back to clients.

Some computers may have restrictions on the firewall, so would you recommend using HTTP traffic, a custom port, or perhaps through SSH or some existing protocol?

Can someone offer some advice (threads, multiple queries of one element?), Tools, databases (mySQL?) Or APIs that will help me get started on this project? I would prefer C ++ for the backend, as it will be faster, but using Java will allow me to reuse the code.

Thanks!

+4
source share
2 answers

I would not use C ++ because of speed alone. It is very unlikely that the difference in performance will make a real difference to your game. (Probably your network may have any performance difference if you do not have 10 GigE between the client and server), I would use C ++ or Java, because you will start working with this language first.

+3
source

For those looking for a good network API for C ++, I always suggest Boost.Asio . This has an advantage regardless of the platform, so you can compile the server for linux, windows, etc. However, if you are not too familiar with C ++ / boost patterns, the code can be a bit overwhelming. Look, try it.

In general tips. Given the above description, you seem to need a relatively simple server. I would suggest keeping it a very simple, single-threaded polling cycle. Read the message from the connected clients (wait for a few sockets) and respond accordingly. This fixes any issue with multiple access to your list and other synchronization issues.

I could also suggest before rewriting my original incarnation. Try to improve it, as you stated:

and the system will receive several requests per second, all of which will require sending the list back to clients.

Given that each request removes an item from this list, why not just report your goals, which item has been deleted, and not just send the entire list over the network again and again? If this list is of any significant size, this minor change will lead to significant improvement.

+2
source

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


All Articles