Jump to content
  • Advertisement
Sign in to follow this  
suliman

Basics of networking?

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

Hi Im been doing games in c++ casually for 7 years but never touched networking whatsoever since it seems like such a shore:) My new project is a turnbased economy/management game which would be nice to have multiplayer support for. Where can i start? And what would be the most simple sollution for such a project? I would prefer to have all players do their turn at the same time and when all is done, the actions are "applied to the world"/one turn passes. I know i have to think about actions and in what order they apply but this is the basic idea. Thanks E

Share this post


Link to post
Share on other sites
Advertisement
It sounds like this game lends itself to a client/server model based on the TCP/IP protocol. TCP/IP is what powers most of the internet services we use on a daily basis: the World Wide Web, email, Instant Messaging, etc.

In the client/server model, players (clients) connect to an authoritative entity (the server, typically run alongside the client on the hosting player's computer) issuing requests (buy 10 of that, sell that, etc) which are subsequently validated and possibly executed by the server in accordance with the rules of the game. This results in a change in the authoritative game state (the only true state of the game, held by the server) which is then communicated to all the clients in a timely fashion so that they will always choose their actions based on the most recent information. This model is used by almost all games today, including FPS:es like Counter Strike and MMORPGs like World of Warcraft.

Now, to actually implement this, one must either turn to operating system facilities such as the Socket API (Winsock/BSD Sockets) or a 3rd party middleware such as ENet or RakNet which provide a layer of abstraction on top of the aforementioned OS APIs. However, if I were you I would simply learn the basics of the WinSock API (there's a plethora of guides available) and write a TCP/IP based client/server system.

For more information about socket programming, look no further than this.

Share this post


Link to post
Share on other sites
Quote:
shore:)


Did you mean chore ?

You'll need some client code, and some server code. The server code could run on one of the players' machines (a la "hosting" a game of Quake or whatever), but still needs to run separately from the client code.

Each client would receive the game state, and then let the user do whatever commands he wants to do, and forward those commands to the server.

The server would have a list of the commands issued by each client for the current turn. When all clients have issued their commands, the server can then resolve the commands, send the updates to the clients, and a new turn starts.

You have to consider what happens when one player leaves the keyboard. You probably want a maximum upper time limit on turn length. You want the server to send out a message saying "no more commands" to each client, and when each client has acknowledged this command (meaning the UI on the client can prevent the user from doing more commands), resolve the turn, and send out the "new turn starts" message (which would unlock the command UI on clients again). This is to avoid race conditions where a late player issues a command he thinks is for turn X, but the server has just resolved turn X and thinks it's now turn X+1.

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!