Question

I'd like to send short data from device A (sender) to device B (receiver),
in such way that if device B will save the data then device A must delete it from its storage.

If B won't save or A won't delete communication must be reverted (as if there ware no communication at all)

Communication is made over unstable channel so there is high possibility of it to be broken at some part.

How should I approach this problem?

It can be in C++.

Was it helpful?

Solution

An algorithm over TCP (reliable, ordered, error-checked delivery):

  1. A sends the data to B
  2. B saves the data
  3. B sends OK to A
  4. A deletes the data permanently
  5. B just keep the data (doesn't delete it).

Exceptions:

  • If some of the steps fails, do not execute the next.
  • If B doesn't receive OK from A, B doesn't save data permanently.
  • If A doesn't receive OK from B, A doesn't delete data permanently.

Detailing by node:

A

  1. Sends data to B
  2. Waits for OK
  3. Receives OK
  4. Delete data

B

  1. Receives data
  2. Saves data
  3. Sends OK
  4. Receives OK
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top