简体   繁体   中英

handling multi client in game

i'm working on a game, the game has the server and the clients who connects to rooms to play,every room is a game, and is running on a thread,

now i thought about it and i know i'll need to communicate with all of the players during the game, i'm not sure how to do this, i thought about making a thread for each player which means i will need to open a thread for the room and 1-3 threads for the players!

for a mini-project it's fine yeah, but Theoretically if it was a game with million+ players, that means something like 1m minimum threads,

is it possible for a server to handle so many threads? and is it the right/an ok solution for this problem?

First of all would be extremely hard to synchronize and is a very expensive way of approaching this problem. It would be better to have one thread in which you handle all of the player processing, that way you don't have to worry about thread synchronization between the players. To be honest, if your game doesn't require a lot of processing time, you may be better of with a single thread design on which all the processing takes place rather than having to worry about everything being thread-safe. Obviously, this wouldn't be a favorable solution if you're trying to learn about multithreading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM