Search code examples
network-programmingdata-transfer

How to guarantee the transmission of data over the network?


Imagine 2 machines A and B. A wants to make sure B receives a packet P even if there are network failures, how can that be achieved?

Scenario 1:
1) A sends P over the network to B.
Problem: if the network fails at step 1, B won't receive P and A won't know about it.

Scenario 2 with acknowledgement:
1) A sends P over the network to B.
2) B sends back ACK if it receives P.
Problem: If the network fails at step 2, A won't receive the ACK, so A can't reliably know whether B received P or not.

Having ACKs of ACKs would in turn push the problem 1 step further.


Solution

  • This is a huge problem which has been studied for years. Read about the TCP protocol which guarantees that either the data will be delivered or the sender will (eventually) know that delivery may have failed.

    You can start reading here: https://en.wikipedia.org/wiki/Transmission_Control_Protocol but there are many more helpful and interesting pages about TCP on the web.

    Or you could just use TCP and take advantage of the work that has already been done.