Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing a computer on a LAN to act as a server

Tags:

c++

c

udp

lan

I'm working on a small networked game (LAN only) with one computer acting as a server and all others (including the actual game running on the same computer) acting as clients. Essentially, the server is transparent to users, but exists to simplify state management for me. The basic concept I have now is that each player's computer will say, "Hey, I'd like to play" via broadcasting and will keep a list of the other players on the network. After each player running the game indicates that they are ready, one computer is chosen as the server and the rest default to clients.

When choosing which computer on the LAN to use as a server, is there really any established way to choose one and inform the others?

I've been tinkering with the basic idea of simply having all players' computers pick a random number and have the one with the lowest (or highest, doesn't matter) be the server (regenerating random numbers for computers which roll the same one). Each computer would receive the "rolled" number of the others and could determine which would be the server, after which it could connect to it. It seems crude, but I'm not sure if it matters since all the computers would physically be on the same network within a few feet of each other. Would this do the job adequately or is there a significantly better way?

like image 460
Gemini14 Avatar asked Jun 18 '11 02:06

Gemini14


1 Answers

To be honest with you, I would make the decision a little more complicated than that. I would be inclined to do some basic information gathering to determine which computer has the most power and elect that one to be the sever (power is intentionally a vague term because the most powerful computer will depend on the requirements of the sever and the game). Give that the server will need to run an additional piece of software (the server in addition to the game) it stands to reason that unless all of the computers have equal specifications, there would be one better suited to the task than the others. As long as all of the nodes are running the same evaluation on the data, they should all reach a consensus as to who should lead or you could have the first node that created the game be responsible for determining which node should be the server.

It may also be worth having the server set up to periodically reassess it's qualifications to be the sever. For instance, background processes could start that would hinder it's ability to perform adequately, or a more powerful node could join the game. Obviously shifting the sever hosting the game would be nontrivial, but it's something to think about. (keep in mind, this happens in online gaming i.e. Halo. When the all client connectivity to the sever drops below a certain threshold, the game is paused and reestablished on a different server that can provide better performance).

like image 73
Chris Thompson Avatar answered Sep 23 '22 15:09

Chris Thompson