You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/flow/advanced/server-client-communication.adoc
+14-12Lines changed: 14 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,14 @@ order: 800
7
7
8
8
= Sync Server & Client UI States
9
9
10
-
Server to client communications contain the synchronization tokens -- `syncId` (server-to-client) and `clientId` (client-to-server) -- for communicating and UI state tracking. This tracking is meant for ordering messages. It's also used to verify that both sides are in the same known state.
10
+
Server to client communications contain the synchronization tokens for communicating and UI state tracking. This tracking is meant for ordering messages. It's also used to verify that both sides are in the same known state.
11
+
12
+
== Synchronization Tokens
11
13
12
14
The `syncId` token marks the state of the server and is returned as received by the client. Whereas, the `clientId` token is incremented for each message sent by the client, with the server incrementing to match the next id in the response. Both `syncId` and `clientId` are integers.
13
15
14
16
15
-
==== `syncId`
17
+
===syncId
16
18
17
19
The `syncId` holds the latest communication state identifier given by the server. It's generated as a strictly increasing id for each response to every request from the client.
18
20
@@ -23,7 +25,7 @@ The initial value when no response has been received from the server is `UNDEFIN
23
25
The `syncId` is always incremented by 1 after a new UIDL response is generated. The client then handles the received messages according to the `syncId` and the latest handled `syncId`, so that changes are handled in the correct order.
24
26
25
27
26
-
==== `clientId`
28
+
===clientId
27
29
28
30
The `clientId` holds the latest communication state identifier given by the client. The client token is incremented on the client after sending the message. The server increments the value in the response to match the next expected `clientId` (i.e., client updated after message sent).
29
31
@@ -32,39 +34,39 @@ On the client, pending messages are removed from the queue as handled when `clie
32
34
On the server, in cases where the id is the previous one with the same request payload, the server re-sends the latest response since the client probably didn't receive the message. If the client-sent id doesn't match the server-expected id, a re-synchronization is initiated.
33
35
34
36
35
-
= UI State Re-Synchronization
37
+
== UI State Re-Synchronization
36
38
37
39
Re-synchronization occurs when the client detects that its state is no longer in sync with the server. This can happen due to unexpected network interruptions, or inconsistencies between the client-side UI and server-side state caused by misconfigured reverse proxies or session replication setups.
38
40
39
41
Several factors can lead to message loss or unexpected message identifiers:
40
42
41
-
- *Incorrect load balancer or reverse proxy configuration:* Using setups without sticky sessions may result in receiving messages from the server which were meant for a different session or UI.
42
-
- *Firewall or Virtual Private Network (VPN) interference:* Deep packet inspection can block certain packets.
43
+
- *Incorrect load balancer or reverse proxy configuration*: Using setups without sticky sessions may result in receiving messages from the server which were meant for a different session or UI.
44
+
- *Firewall or Virtual Private Network (VPN) interference*: Deep packet inspection can block certain packets.
43
45
44
46
These factors might also generate a delay in arrival of the messages. Virus scanners are particularly problematic and may cause issues when `WebSocket_XHR` is used. Increasing the `maxMessageSuspendTimeout` parameter value could help mitigate message arrival delays.
45
47
46
48
Other potential causes include:
47
49
48
-
- *Faulty router hardware:* This could be due to routers using outdated firmware versions.
50
+
- *Faulty router hardware*: This could be due to routers using outdated firmware versions.
49
51
- *Unstable Wi-Fi or cellular connections*: Fluctuating network conditions can disrupt communication.
50
-
- *Server-side issues:* Request-handling hiccups may lead to inconsistencies, possibly due to server performance degradation.
52
+
- *Server-side issues*: Request-handling hiccups may lead to inconsistencies, possibly due to server performance degradation.
51
53
52
54
53
-
== Re-Synchronization Initiation & Mechanism
55
+
=== Re-Synchronization Initiation & Mechanism
54
56
55
57
Re-synchronization is initiated by the client when it can't find a message with the expected `syncId` among the pending messages from the server within a given timeout. The default is 5 seconds, which is configurable using the `maxMessageSuspendTimeout` parameter. Below is the process followed to re-synchronize:
56
58
57
-
*Client Initiation:*
59
+
*Client Initiation*:
58
60
59
61
- The client clears the queue of pending messages from the server.
60
62
- It terminates the current request and sends a re-synchronization request to the server.
61
63
62
-
*Server Handling:*
64
+
*Server Handling*:
63
65
64
66
- Upon receiving the re-synchronization request, the server invokes the detached listeners of UI components and re-attaches all components to the state tree.
65
67
- The server then sends a response that includes the current UI state needed to rebuild the client-side state tree.
66
68
67
-
*Client Update:*
69
+
*Client Update*:
68
70
69
71
- The client receives the updated UI state from the server.
70
72
- It clears all old pending messages, updates the last known `syncId` to the newly received value, and rebuilds the DOM tree from scratch based on the server's current state.
0 commit comments