Questions about hosting and playing.

Hi there.

When designing a game where the server is inside the game itself (no centralized server running somewhere else), where one of the players is the host, and the others join the game…

Do you treat the host differently with regards to network code? Do you build custom written code for the game host, or do you treat the host like any other player? I mean, if I treat it like any other player, I will be taxing the network code more than I need to, however it’s obviously the easiar way to go. Since the host player will be able to talk to the server directly, custom code could make things more efficient, but by how much? Is it worth it? Does anyone have any experience as to what normally works out for the better?

Like all “performance issues” there is no accurate answer to your questions in the abscence of a detailed game description.

However, performance on localhost using the networking layer is pretty fscking good in general so long as it uses the loopback interface (127.0.0.1) and not the external interface; Just make sure you connect on 127 / localhost when connecting to the local server.

There’s significant overhead to using lo, but you’re never going to notice it in a non-dedicated-server game - it will be dwarfed by your other issues (*)

(*) modulo my first sentience above; i.e. I’m sure you could come up with many situations or several where you do notice. But since you’ve not described the game, you probably want an inaccurate, finger-in-the-air answer, so here ya go :slight_smile:

Thanks :slight_smile:

Yes, I was looking for more or less a “general rule of conduct” in the matter. I was not sure exactly how networking over localhost worked (Faster than remove networking is obvious, but I was not sure just how fast it was).

In my specific game, your answer confirmed my initial thoughts of handling the host as any other player.

The game is a turn-based board game, where each “action” (usally moving units, playing cards) are performed in cycles, so networking is always completed for one player before it begins on the next player. So, the network part of this specific game is pretty stressless. However, I always keep in mind how I can “generalize” the code for later, (if only with commenting the code), so I wanted to ask this question to get some general feedback. Which I did. So, all is good :wink:

Short answer is that on a LAN, for almost any conceivable data-transfer use, bandwidth is effectively infinite and latencies are effectively infintessimal.

So yes you can treat the host like any other client and no its not really worth doing any special coding.

Many games will in fact actually launch a seperate process for the server. This was staretd by Quake2 and is still commo ntoday (ie all the Bioware NWN engine games do this… NWN, KOTR, KOTRII, etc)