Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
88 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 Architecture
 On to WinSock
 The Basics
 Socket Types
 Error Checking
 The price you
 pay...

 Rock, Paper,
 Scissor, Shoot!

 How to use
 the demo

 A word on lag
 Conclusion

 Demo
 Printable version

 


Rock, Paper, Scissor, Shoot!

Here comes the cool part. We will program a multiplayer game using WinSock. The game will be client - server because I find it a more user friendly model than client - client. We will program two independent applications: RPSS and RPSSS. RPSS is Rock, Paper, Scissor, Shoot (the client). RPSSS is Rock, Paper, Scissor, Shoot Server (the server).

The server's features are:

  • Small, simple, console application
  • Lobby type architecture that waits for two clients to join
  • Blocking sockets

The client's features are:

  • Infinite game rounds
  • Graphics
  • Asynchronous sockets

A feature that both the client and the server share is that I have implemented a quit mechanism so if the server realizes that a client has quit, he will also stop the client that is still connected. This is good since it helps eliminate pointless errors when one client has suddenly quit.

We need to develop the protocol we will use to communicate between the two clients and the server.

We can just use this:

#define RPSS_NUMOFUSERS 0x03 #define RPSS_STARTGAME 0x04 #define RPSS_SCISSOR 0x05 #define RPSS_ROCK 0x06 #define RPSS_PAPER 0x07 #define RPSS_QUIT 0x08

So each buffer of data that we transmit is 2 bytes long. The first byte is one of the above commands and the second is a parameter. For example the first byte we transmit is RPSS_NUMOFUSERS and the second is 2. If you think about it, the only command that actually needs a parameter is RPSS_NUMOFUSERS, so if we took that away, we would just be transmitting one byte instead of two.

In which order should I program client - server games? I'm trying to figure that out right now!

My opinion is:

  1. Create the protocol with which client and server will communicate.
  2. Start coding to the server up to where the connection is accepted.
  3. Start coding the client up to the part where the server accepts the connection.
  4. Now code your way, step-by-step, through sending and receiving data for both the client and the server.



Next : How to use the demo