문제

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++.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top