Choosing a computer on the local network to work as a server

I am working on a small network game (only with a local network) with one computer acting as a server and all the others (including a real game running on the same computer) acting as clients. In essence, the server is transparent to users, but exists to simplify state management for me. The basic concept that I have now is that each computer player will say “Hey, I would like to play” through the broadcast and saved a list of other players on the network. After each player playing the game indicates that they are ready, one computer is selected as the server, and the rest are selected by default as clients.

When you choose which computer on the local network to use as a server, is there really any established way to select and inform others?

I dealt with the main idea of ​​simply having computers of all players choosing a random number, and having one with the lowest (or highest, it does not matter) server (random number recovery for computers that pump the same one). Each computer will receive a “rolled” number of others and can determine which one will be the server, after which it will be able to connect to it. This seems rude, but I'm not sure if it matters, since all computers are physically on the same network a few feet apart. Will this do the job adequately or is there a significantly better way?

+6
source share
1 answer

To be honest with you, I would make a decision a little harder than that. I would be inclined to do some basic information gathering to determine which computer has the most power and choose that it should be a split (power is intentionally an indefinite term, since the most powerful computer will depend on the requirements of the split and the game) Let the server need run an additional piece of software (server in addition to the game). Of course, if all computers do not have the same specifications, then it is best suited for this task than others. As long as all nodes perform the same data assessment, they must reach a consensus as to who should lead, or you may have the first node that created the game, be responsible for deciding which node should be the server.

It may also be worthwhile to establish that the server is configured to periodically reassess its qualifications as a split. For example, background processes may begin that would interfere with its ability to perform adequately, or a more powerful node could join the game. Obviously, transferring the host as the game progressed would be non-trivial, but that's what to think about. (Remember, this happens in online games, i.e. in Halo. When all client connections to the connector drop below a certain threshold, the game pauses and restores on another server, which can provide better performance).

+5
source

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


All Articles