To get started, the sequence variable in the code is basically the message identifier. There are two ways in which a single request attempt can fail:
- Request message simply cannot send
- A request message is sent, but the client gets tired of waiting and the time runs out before the response returns to it.
In the second case, if you do not have a sequence number, you do not know which of your requests is actually the one that succeeded.
Consider this customer story:
- Send Request # 1
- Time-out
- Send Request # 2
- Time-out
- Send Request # 3
- Get an answer
Which request triggered the response? This can be any of the three requests due to the second type of request failure mentioned above. The sequence number in the response, we can know exactly which request is processed by the server.
The idea of an “incorrect response from the server” in the client’s sample is that if the client is on request No. 3 (waiting time on requests No. 1 and No. 2), he discards answers #n (where n <3) until he receives a response # 3, which he accepts.
To send more than the serial number, use the serialization format and send the whole object.
For example, I could define a class MyRequest { int sequence; string text; } class MyRequest { int sequence; string text; } class MyRequest { int sequence; string text; } , and then send it as JSON to the server.
An infinitely increasing sequence variable could be replaced with int64, and then that would be nice, or you could do something like a GUID as an identified request.
source share