Sign in to follow this  
baker

basic network questions about a simple game like pong.

Recommended Posts

hi, i am somewhat new to game network programming and have a few questions. if i plan on making a pong game have functionality where i can play a friend over a network how is this done? i assume there would be 2 clients and 1 server. the server that handles and controls everything basically the brain(check collisions, updates screen info on both client machines, controls game states, etc...) so for every action on the client machine, i assume a packet will be built and sent to the server. now for a game like pong, how often are packets built and sent? like if a user is holding down the button to move the paddle to the left, i assume this action is many times per second (maybe 50?). now is a udp packet built and sent 50 times per second? if so, now the server replies to both clients that many times per second to refreash all game objects on both screens? if the server is the brain keeping track of incoming messages from both clients and sending msgs to both clients, this pong game will have to incorporate threads correct? and if both players both performing an action, will this pong game have to incorporate a queue of some sort? like if both clients are both performing an action (moving each of their paddle to the left) this server will have to recieve each packet, calculate what to do, send updates. ????

Share this post


Link to post
Share on other sites
I think you are making the problem way more difficult than it has to be.

My 2 cents. Ignore if want

If you dont need any type of matchmaking then I dont see the need for a server. Each client sends the position of its paddle/ball to the other client. The clients interpolate the position of the ball and extrapolate (if needed) the position of the paddle. The clients should do the their own collision detection. You can also send event information back in forth to keep things in sync(scoring,time, etc). Since there is constant two-way communication between the two clients you might be able to get away with using TCP since ACKs will be piggybacked.

This is a two player model and does not scale well for more than a few players. If you wanted to have many players then the server/client model is much better.

Share this post


Link to post
Share on other sites
BlueHabu's suggestion is great if your goal is to have a functional pong clone. If your goal is to learn more about network architecture so you can grow and develop larger projects, do yourself a favor and "over complicate" things as much as you can. My first pong clone featured a dedicated server and in theory would have been easily expandable to function as a pong game center type thing (e.g. hosting multiple games at once). [grin]

Share this post


Link to post
Share on other sites
Quote:
Original post by baker
hi,
i am somewhat new to game network programming and have a few questions. if i plan on making a pong game have functionality where i can play a friend over a network how is this done?

i assume there would be 2 clients and 1 server. the server that handles and controls everything basically the brain(check collisions, updates screen info on both client machines, controls game states, etc...)

so for every action on the client machine, i assume a packet will be built and sent to the server. now for a game like pong, how often are packets built and sent? like if a user is holding down the button to move the paddle to the left, i assume this action is many times per second (maybe 50?). now is a udp packet built and sent 50 times per second? if so, now the server replies to both clients that many times per second to refreash all game objects on both screens?

if the server is the brain keeping track of incoming messages from both clients and sending msgs to both clients, this pong game will have to incorporate threads correct? and if both players both performing an action, will this pong game have to incorporate a queue of some sort? like if both clients are both performing an action (moving each of their paddle to the left) this server will have to recieve each packet, calculate what to do, send updates.

????


Make a pong game unlike any other with 1 server and 2 clients. Make it as precise and accurate as possible. Open up a new path for multiplayer games with the ultimate collision. It all starts with pong.

Share this post


Link to post
Share on other sites
yea, that is kind of my goal. i would like to get an understanding about networked applications and what a fun way to do this by creating a game.


Quote:
Original post by graveyard filla
BlueHabu's suggestion is great if your goal is to have a functional pong clone. If your goal is to learn more about network architecture so you can grow and develop larger projects, do yourself a favor and "over complicate" things as much as you can. My first pong clone featured a dedicated server and in theory would have been easily expandable to function as a pong game center type thing (e.g. hosting multiple games at once). [grin]


Share this post


Link to post
Share on other sites
One thing to think about is that the clients only need to communicate with the server when their "state" changes. In your paddle moving example, let's say I press down the Left Arrow to move my paddle to the left. Rather than spamming the server with "Move Left" packets, one could be sent when I press the key and one when I release it, and the client and the other server could figure out everything in between.

Share this post


Link to post
Share on other sites

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