Sign in to follow this  

Pong Server/Client

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

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?

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

This topic is 4354 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this