Jump to content
  • Advertisement
Sign in to follow this  
Elric

Server-Client structure without a dedicated server

This topic is 3812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Suppose a game uses server-client structure without using a dedicated server. When I start the game, I have the option to assign my computer as server also. There are many games like that. How do they construct this structure? I mean, is the server computer being hybrid of server and client? Or maybe when I select my computer as a server, it may start a server thread and let my game continue processing as a client that connects to that server thread? So there should be 100% server-client structure with no need to run an external server exe. Also I saw some code examples that seperates the chunks of code with if statements of server or client, embedding both to the same code. But this should be kind of hard when the code gets complicated... What do you think the best way should be? Thanks...

Share this post


Link to post
Share on other sites
Advertisement
The P2P-Like structure that I have seen is that one person runs a server and others connect to it. Firstly, the person hosting the session runs a server. That server does nothing but relay calls and whatever game logic that is network based. The person that is hosting that session connects to that server using a client system. So the person hosting has two jobs - Hosting using a server system, and connecting to his own server using a client system. Then, others can connect to that server in the same manner.

Player1: setup Server (Host system).
Player1: connect to server (using client system).
Player2: connect to server (using client system).
Player3: connect to server (using client system).
etc.

This gets rid of reliance on a central server.

As for processing, You can run a client and server in blocking or non-blocking mode. Blocking mode, obviously, blocks processing until it it receives a signal from whatever it is connected to. This requires threading and mutexing to relay the signals properly. Alternatively, you can make a non-blocking call to the connection to see if anything has arrived. Its a bit trickier to set up but it fits well with the message loop of your renderer.

Structure can be in the same class, or in different classes. Essentially a server is a client, but with extra logic to manage connections and timeouts, etc.

Share this post


Link to post
Share on other sites
What would be the advantage of this over p2p? I am currently looking at either this system or a straight p2p system. Obviously only one player needs 'decent' bandwidth ( server ) but which is 'better'?

Share this post


Link to post
Share on other sites
A person, in a true P2P system, is both a server and a client. In the aforementioned system, only one person is the server and the client while all other others are just clients. Also, a P2P system is hard to manage because its a string of connections, so player A might not be connected to player C directly, rather he would be connected through player B, and so on.

I'd advise against this, go with the simplest approach discussed above. Its much easier to implement and manage. P2P systems don't offer anything over this system other then decentralization.

Share this post


Link to post
Share on other sites
I would definitely consider the possibility of running the server as a separate exe file, however you could run it from the same code as the single player game. If the single player game is set up in such a way that it has the game loop running and the player and AIs send their commands in to that loop, you could essentially just change where those commands are allowed to come from.

For example.
Single player runs the game
The game core initialises and opens "connections" for each player (the player and AIs)
These connections are handled by an internal method that chooses whether to use a network connection or another piece of code running within the game, probably worth using a thread for each AI to run its own decisions.

The "connection" in this case would simply be a thread, instead of a TCP client or whatever. If you separate the main loop and input structure, you can make the input structure accept input from wherever you want.

So you then go multiplayer, the input methods just need to accept network connections for the input instead of whatever AI thread. This could also allow the possibility of running some of the AIs on client systems to take stress off the server if you are playing a game (for example) with 4 players and 4 AIs, run 1 AI on each system.

Just a possibility for you, hope it helps


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!