Skip to content

Commit

Permalink
feat: server to client communication
Browse files Browse the repository at this point in the history
Start server to client communication
documentation with
syncId and clientId information.

Fixed #3911
  • Loading branch information
caalador committed Nov 29, 2024
1 parent f5656af commit 65ad5ff
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions articles/flow/advanced/server-client-communication.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Server to Client Communication
description: The more technical details of how the server to client communication works.
order: 800
---

= Server to Client Communication

Server to client communication contains the tokens `syncId` and `clientId` for communication tracking.
This tracking is for keeping the order of messages and to verify that both sides are in the same known state.

The `syncId` token marks the state of the server and is only replayed by the client.

The `clientId` token is incremented for each message sent by the client, with the server incrementing to match the next id in the response.


==== syncId

Check warning on line 17 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.HeadingCase] 'syncId' should be in title case. Raw Output: {"message": "[Vaadin.HeadingCase] 'syncId' should be in title case.", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 17, "column": 6}}}, "severity": "WARNING"}

Check failure on line 17 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'syncId'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'syncId'?", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 17, "column": 6}}}, "severity": "ERROR"}

The `syncId` holds the latest response id given by the server.

It is generated as a strictly increasing id for each response to every request from the client.
This id is replayed back to the server on each request from the client.
This helps the server know the state of the client and to compare it against its own state.
If there has been changes on the server since the received `syncId`, the serve can try adjusting the handling client actions.

Initial value when no response has yet been received from the server is `UNDEFINED_SYNC_ID(-1)`.
This value is seen between the bootstrap HTML loading and first UI render.

Incrementation of the syncId is always by one after a new UIDL response is generated.

Check failure on line 29 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'Incrementation'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'Incrementation'?", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 29, "column": 1}}}, "severity": "ERROR"}

Check failure on line 29 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'syncId'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'syncId'?", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 29, "column": 23}}}, "severity": "ERROR"}
The client then handles the received messages according to the syncId and latest handled syncId, so that the changes are handled in the correct order.

Check failure on line 30 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'syncId'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'syncId'?", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 30, "column": 64}}}, "severity": "ERROR"}

Check failure on line 30 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'syncId'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'syncId'?", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 30, "column": 90}}}, "severity": "ERROR"}


==== clientId

Check failure on line 33 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'clientId'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'clientId'?", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 33, "column": 6}}}, "severity": "ERROR"}

Check warning on line 33 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.HeadingCase] 'clientId' should be in title case. Raw Output: {"message": "[Vaadin.HeadingCase] 'clientId' should be in title case.", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 33, "column": 6}}}, "severity": "WARNING"}

The `clientId` holds the latest request id given by the client.

The client token is incremented on the client after sending the message, the server increments the value the response to match the next expected clientId (client updated after message sent).

Check failure on line 37 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'clientId'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'clientId'?", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 37, "column": 146}}}, "severity": "ERROR"}

On the client:

- Pending messages are removed from the queue as handled when clientId from server matches next expected value.

Check failure on line 41 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'clientId'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'clientId'?", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 41, "column": 63}}}, "severity": "ERROR"}
- If id is less than the expected client waits as server has not yet seen all messages and the response probably will arrive later.

Check warning on line 42 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.Will] Avoid using 'will'. Raw Output: {"message": "[Vaadin.Will] Avoid using 'will'.", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 42, "column": 114}}}, "severity": "WARNING"}
- Other cases client will trust the server and update the id to server expectations.

Check warning on line 43 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.Will] Avoid using 'will'. Raw Output: {"message": "[Vaadin.Will] Avoid using 'will'.", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 43, "column": 22}}}, "severity": "WARNING"}

On the server:

- In cases where the id is the previous with the same request payload the server will resend the latest response as it is probable the client didn't receive the message.

Check warning on line 47 in articles/flow/advanced/server-client-communication.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.Will] Avoid using 'will'. Raw Output: {"message": "[Vaadin.Will] Avoid using 'will'.", "location": {"path": "articles/flow/advanced/server-client-communication.adoc", "range": {"start": {"line": 47, "column": 82}}}, "severity": "WARNING"}
- If client sent id doesn't match the server expected id a re-synchronization is initiated.

0 comments on commit 65ad5ff

Please sign in to comment.