Variable synchronization between client and server

Let's say I have a client variable counter. When I send a request to the server, I send this value to the variable and then increment it by one (for the next request to the server). The server monitors this counter independently and checks that the account sent by the client is 1 more than its own (server) copy of the account. This is all fine and dandy, but consider the following situation:

  • The client sends, say, 23 to the server.
  • The server receives 23, checks it, and increments its own counter to 23.
  • The server returns an All-Okay code to the client

but -

On the way from the server to the client, the return code is corrupted. Thus, the client believes that the server has not updated its counter, and therefore it leaves the client counter at 23. From this point, the client and server are not synchronized.

Does anyone know of any reliable schemes that could work in the face of such possible corruption / errors?

Thanks
Cameron

+3
source share
3 answers

"nonce" 64- . , , nonce , . , , nonce .

nonce . , , .

, , . nonce , .

+2

- , , .

, TCP, , .

, , , . - . "increment". "set".

+1

, .

:

, ( ) ( )

, . , , , , , . . .

If you are concerned about corruption, calculate the checksum in the message and send it. Recount the checksum upon receipt and compare it with the sent one. Typically, the network stack does this for you, so I wouldn't worry too much about it if you don't have your own protocol.

+1
source

Source: https://habr.com/ru/post/1698441/


All Articles