0
\$\begingroup\$

so i want to create a simple game that runs over a network but I am having trouble deciding what needs to be done in terms of what the server needs to do and what the clients need to do. I understand I should use UDP sockets but I am unsure how to implement it within a game and have all the clients be in sync. Should the server side have like a master copy of the game where i basically runs the game and accepts moves, plays them in itself, and then sends the current state of the object to the other clients?

\$\endgroup\$
  • \$\begingroup\$ Search more and try stuff. You won't learn anything if we code it for you. "Should the server side have like a master copy of the game where i basically runs the game and accepts moves, plays them in itself, and then sends the current state of the object to the other clients?" Asking the question is answering it. \$\endgroup\$ – Vaillancourt Mar 5 '16 at 12:59
4
\$\begingroup\$

In most of cases the relationship is simple:

Client -> Input to server
Server -> Calculate logic and physics, send object position and property data back to client
Client -> Render the scene using received data

I guess that this is what you where asking for!;)

\$\endgroup\$
  • \$\begingroup\$ oh ok thanks! so if this was a simple game of pong for example, the client would send the input of when you click a key to the server and the server would return the new coordinates of the paddle and it would check if the ball collides and return the new state of the ball? \$\endgroup\$ – J leong Mar 5 '16 at 8:27
  • \$\begingroup\$ If client clicks a key, it sends the input to server. Than server checks the key and, if it was, for example, up arrow key, than it moves player's object upwards. However, server does calculations all the time, even if there's no input. It needs to calculate the ball's position and send it to the client. And than client renders the ball in it's new position. \$\endgroup\$ – Adrians Netlis Mar 5 '16 at 8:39
  • 1
    \$\begingroup\$ You should probably also try to predict where things are moving or the screen will basically freeze on the client. \$\endgroup\$ – ZEKE Mar 5 '16 at 9:31
  • \$\begingroup\$ If you have 30 ms or smaller ping(my internet connection with a normal server is around 20 ms ping) than you don't need to. Elseway you need to do some linear math using current linear velocity and applying it duirng connectionless frames. Hm... This can lead to some incompletnesses. But relationship delays can cause some input problems. Uh... Propably we need good internet connection... \$\endgroup\$ – Adrians Netlis Mar 5 '16 at 10:45
  • \$\begingroup\$ Also consider that if any processing overhead is taken on by the host, you potentially reduce the power required on the client side; Allowing users with lower-specced models to access your game. \$\endgroup\$ – Gnemlock Mar 5 '16 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.