Jump to content
  • Advertisement
Sign in to follow this  
Stompy9999

Server question

This topic is 4895 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

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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().

Share this post


Link to post
Share on other sites
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.

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!