Pong Server/Client

Started by
3 comments, last by LorenTapia 18 years, 3 months ago
Hello, I am using Pong for my first client/server game using MSVC and WinSock2. basically there is a receive thread on both the client and server sides. Server Side: When player moves a message is sent to the client When the ball moves a message is sent to the client Client Side: When the player moves a message is sent to the server I soon realized that on an internal network there really isnt lag issues but over the internet there is a tad bit...and this is a basic game. I was thinking of setting an interval in m/s for the server to send to the client information about a paddle movement and/or ball movement. And when the client recieves something from the server to send back a response to the server with the clients coord. Am i heading in the right direction and if so...what is a good interval to use to send packets from the server to client?
Advertisement
I have also made a client/server style pong game (we called it Pizzong). The way we got it to work was by use a "logic lock" where the client did not process a logic until it received a packet telling it to logic (1 byte per logic packet). When a player presses a button, it sends a packet to set the button state to down. The server will then send a Logic packet that says that player X has his buttons in X state. You can also reduce packet size by using bit flags. Make sure that your packets stay in the right order, we were have problems with that where one packet would get there before another packet (some how?). Hope this helps. Should I elaborate more?
=Loren Tapia=
I asked about the same thing some days ago, check it out:
http://www.gamedev.net/community/forums/topic.asp?topic_id=368440

Also, theres a nice discussion about the syncing of such games in this thread (starts about halfway):
http://www.gamedev.net/community/forums/topic.asp?topic_id=368408
So when the the server side realized that a key was pressed and a ball movement, it send a logic packet to the client. Did this occur at the very instance a key or ball moved or at some specified interval. Also when the client receieved the logic packet did it instantly repond with its own logic packet specifying its movement...or was a logic packet sent to the server the very instant the client had a movement.

It is indeed a different world when using client/server games...what a learning experience.

I will definately look into bit flags.

I am going to read the post above as well...it must have appeared while i was making this post.
The idea of this model is based on the premise that if both clients are going to have the same exact logic happing on each machine, they will be able to stay synced if they only perform a 'logic' when the server tells them too. So if you want the game to operate at 30 logics per Second, the server will need to send 30 packets per second.

// Client sends  this packet when they have a key state changeclass KEY_PACKET {public:     bool Up, Down;};//// Server sends thease packets// Basic logic packet class LOGIC_PACKET {   public:   unsigned char id;};// The logic packet is sent whe there was a KEY_PACKET sent to it class LOGIC1_PACKET : public LOGIC_PACKET {public:    short player;     bool Up, Down;};


And if a player presses a button, (key state change), they send a packet with what they want there key state to be in.

When the server receives the key state change packet, its next logic packet will then also contain the new key state.

So each player will perform the same logic on the same input. You will usually only send 1 byte of data per logic. I am sure there are better faster ways of doing this, but this was what worked for me.

[Edited by - LorenTapia on January 19, 2006 8:19:17 PM]
=Loren Tapia=

This topic is closed to new replies.

Advertisement