Server question

Started by
3 comments, last by John Schultz 18 years, 10 months ago
I just read this article to understand a little about network programming. It may be old, but it helped me understand some things about Winsock. Anyway, my problem with the example program in the article is that you must Run a seperate program to start the server and to actually play in the server. I see in other games that the player can create their own server and then play in that server, rather than having to load up another program. How do I do this, though? Sorry if I'm not being that clear, I'm still trying to understand most of this. Thanks!
-----------------------------Play Stompy's Revenge! Now!
Advertisement
From the UI, allow the player to start a game (as a server), or join an existing game (as a client).
In the source code, check to see if the game is running as client or server, with different code blocks for each:

  if (networkSystem->isServer()) {  // Perform server code.  } else {  // Perform client code.  } // if
Okay, Thanks so much!
-----------------------------Play Stompy's Revenge! Now!
to be honest, i dont see a need to constantly check if IsServer() is true... instead, you should use a function pointer or a virtual function to handle this. e.g., networkSystem->Update().
FTA, my 2D futuristic action MMORPG
Quote:Original post by graveyard filla
to be honest, i dont see a need to constantly check if IsServer() is true... instead, you should use a function pointer or a virtual function to handle this. e.g., networkSystem->Update().


The if (isServer()) blocks will used throughout the game code, primarily to send game events. One advantage to the if-block method is that server and client code remains side-by-side. In many cases it will be hard to cleanly separate such code blocks without duplicating code.

Message dispatch on the client is most efficiently implemented with a jump table of function pointers or functors (class/struct with an implemented virtual function and any special code/data to perform the call (for example, a proxy/caster to deal with multiple inheritance member function calls (this was for an existing project that used mulitple inheritance)).

In cases where it is possible to elegantly modularize code with function pointers or virtual functions in the dual-use (client/server) game code, there won't be a significant performance difference between the two methods. Thus, the choice comes down to choosing a method that promotes implementation of smaller code and code that is easier to develop and maintain.

This topic is closed to new replies.

Advertisement