# How to Sync Up Two Flash Clients in AS3?

**URL:** <https://forum.kirupa.com/t/how-to-sync-up-two-flash-clients-in-as3/634155>\
**Category:** flash\
**Created:** [January 19, 2016, 3:18am UTC](https://forum.kirupa.com/t/how-to-sync-up-two-flash-clients-in-as3/634155 "2016-01-19T03:18:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Twisted4000](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Twisted4000](https://forum.kirupa.com/u/Twisted4000)\
**Post date:** [January 19, 2016, 3:18am UTC](https://forum.kirupa.com/t/how-to-sync-up-two-flash-clients-in-as3/634155/1 "2016-01-19T03:18:48Z")

</div>

I’m making a 2-player fighter Flash game that has TCP connection, so you can play against another player on a totally different computer. It works, and all of the signals successfully send and get received from each other, but after a while of playing, eventually the characters on the screen go out of sync. Like, on one client, a character will be towards the edge of the map, and other the other client, the same character is in a completely different spot. I don’t understand why this is, considering the same exact messages are being sent to both clients. I heard I have to sync up the clients with a “tick rate” or something? I’m completely lost on this, anyone have any ideas? Thank you.

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [January 19, 2016, 9:46am UTC](https://forum.kirupa.com/t/how-to-sync-up-two-flash-clients-in-as3/634155/2 "2016-01-19T09:46:29Z")

</div>

Hey Twisted,

Yeah, the simplest way to handle the problem is to periodically have the server (there must be a server or a master client if you don’t want to delve into more complex topics) broadcast the global state that all clients must display in order to be correct. So if you’re sending messages like “walk RALPH forward 5 pixels”, your master broadcaster needs to send messages like “RALPH’s absolution position is 305” at some rate that mitigates whatever drift you’re seeing.

> [@Twisted4000](#):
>
> I don’t understand why this is, considering the same exact messages are being sent to both clients.

There are a bunch of timing issues that Flash doesn’t help you with at all here. Player 1 may receive three messages at once, and Player 2 may receive them three seconds apart. If you’re applying any amount of gravity, friction, acceleration, or any sort of time-based logic in your game, things are bound to get out of sync. Without going into details in this short post, there are an absurd amount of things that Flash, or AS3, or TCP aren’t going to guarantee when communicating with multiple players.

The problem you’re butting up against in general is very common in computer science (and game programming), and there are many ways to solve it for various types of applications. Games tend to rely on the master server approach to 1) prevent cheating and 2) make things easy to program and reason about. _But_, there are tons of interesting things to read about on the topic if you’d like to do so:

> **[Netcode](https://en.wikipedia.org/wiki/Netcode)**
>
> Netcode is a blanket term most commonly used by gamers relating to networking in online games, often referring to synchronization issues between clients and servers. Players often infer "bad netcodes" when they experience lag or when their inputs are dropped. Common causes of such issues include high latency between server and client, packet loss, network congestion, and external factors independent to network quality such as frame rendering time or inconsistent frame rates. Netcodes may be Unlik...

> **[Real-time computing](https://en.wikipedia.org/wiki/Real-time_computing)**
>
> Real-time computing (RTC) is the computer science term for hardware and software systems subject to a "real-time constraint", for example from event to system response. Real-time programs must guarantee response within specified time constraints, often referred to as "deadlines".
> The term "real-time" is also used in simulation to mean that the simulation's clock runs at the same speed as a real clock.
> Real-time responses are often understood to be in the order of milliseconds, and sometimes mic...

> **[Consensus (computer science)](https://en.wikipedia.org/wiki/Consensus_(computer_science))**
>
> A fundamental problem in distributed computing and multi-agent systems is to achieve overall system reliability in the presence of a number of faulty processes. This often requires coordinating processes to reach consensus, or agree on some data value that is needed during computation. Example applications of consensus include agreeing on what transactions to commit to a database in which order, state machine replication, and atomic broadcasts. Real-world applications often requiring consensus in...

> **[Paxos (computer science)](https://en.wikipedia.org/wiki/Paxos_(computer_science))**
>
> Paxos is a family of protocols for solving consensus in a network of unreliable or fallible processors.
> Consensus is the process of agreeing on one result among a group of participants. This problem becomes difficult when the participants or their communications may experience failures.
> Consensus protocols are the basis for the state machine replication approach to distributed computing, as suggested by Leslie Lamport and surveyed by Fred Schneider. State machine replication is a technique for...

> **[Spanner (database)](https://en.wikipedia.org/wiki/Spanner_(database))**
>
> Spanner is a distributed SQL database management and storage service developed by Google. It provides features such as global transactions, strongly consistent reads, and automatic multi-site replication and failover. Spanner is used in Google F1, the database for its advertising business Google Ads as well as Gmail and Google Photos.
> Spanner stores large amounts of mutable structured data. Spanner allows users to perform arbitrary queries using SQL with relational data while maintaining strong ...
