Synchronization in multiplayer networked game?
Asked Answered
H

1

5

Recently I have been working on a multiplayer networking app. I had successfully implemented the client server model using Bonjour services and NSStream objects. The two way communication has been done successfully.

The problem I'm facing is: the two devices running the app are connected via local wifi. There is a latency problem while sending the messages from client to server and vice versa.

Describing in brief:

  • It's a car racing game with at most two players.
  • One server and other client.
  • When client press the buttons a particular message is sent to the server telling which key or button was pressed. Then the server responds accordingly and make changes on the client's car on the server itself. These changes are not always the same. There is always a difference between the actual location of the car on the client's screen and that in the server screen.

Any ideas?

Helton answered 29/4, 2011 at 13:22 Comment(6)
Maybe instead of sending key presses to the server you should only send the state of the car to the server. like speed, x,y,z position. This way there won't be lag on the client machine, but there may be inconsistencies between server and client.Above
possible duplicate of Dealing with Latency in Networked GamesBoaster
@Above - oh dear god no. Rule #1 never trust the clientBoaster
@netbrain: This is actually makes synchronization more difficult as you add more players... and, as @Brian Roach says, never trust the client! The server should be the ultimate authoritySalot
then the player playing on the server will always have the advantage?Above
@netbrain: there are never "players on the server". Even if you were to run a session on the server machine, you would usually run a "client" version- but the point here is if you can't trust the server at that point you're up the creek without a paddle ;)Salot
S
10

Welcome to the world of networking. :)

These are the classic difficulties with game networking programming. There's a lot of different techniques to overcome these issues.

This blog has great info on the subject and will probably help you out.

http://gafferongames.com/networking-for-game-programmers/

You may be specifically interested in this article:

http://www.gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking

Good luck!

Salot answered 29/4, 2011 at 13:27 Comment(3)
I just checked out the comment that Brian Roach included to your question with a link to Dealing with Latency in Networked Games and one of the answers given there had a link to an article on how the Source engine handles these issue. It is a great read! You should check out that question.Salot
@All : thanks for leading me in right direction....what i was thinking can i send the client key input to the server and server in return send physics and all updated data to client and then client updates its drawing by using that data....is this will be the right way..??Helton
Yes and know- the big difference nowadays (begging with Quake) was that the client would make "educated guesses" while waiting for the server to return the updates from the user input...there's interpolation and wonderful (read: complicated) things like that to make this who process happen smoothly. Anyway- this all in those links provided. I recommend you read up on those.Salot

© 2022 - 2024 — McMap. All rights reserved.