I have to implement a pseudo TCP handshake that leads into a file transfer. I have no problem doing the file transfer: simple send-acknowledge. What I can't wrap my head around is how to do the three way handshake assuming there will be packet loss during one of the 3 steps.

For instance: My client sends a SYN packet. If it times out (packet loss or just slow) waiting for SYN-ACK, it resends it. Server sends SYN-ACK. If it times out waiting for ACK, resend SYN-ACK. Now how does the client now that his ACK was received?


The client doesn't know that his ACK was received, but why does he care? The connection is established whether or not the ACK is received. You will never know for sure that the last packet sent was received, so you have to design a protocol that doesn't require that.

  • 1
    So why does the TCP protocol require it? Shouldn't the server be expecting it? If it doesn't receive the ACK because it was lost, it'll then receive a data packet. Won't it translate it incorrectly? – user111658 Feb 23 '12 at 5:14
  • 1
    It's the nature of the beast. If you require nothing at all, you don't have any protocol. And you have to tolerate some loss, or your protocol doesn't work. So it's a necessity that you will require some things that the protocol would work fine without. It's an unavoidable consequence of the two generals (or "last ack") problem. – David Schwartz Feb 23 '12 at 5:34
  • 6
    @user111658 If the server doesn't get the client's ACK, it'll resend its SYN/ACK (except if you have SYN cookies enabled, that is - which can implode the connection and freeze the client-side connection when the last ACK is lost in a server-talks-first protocol like SMTP). For your case, when the client's starting the data communication when it believes the connection to be up, its ACK to finalize the handshake is going to be in the header on the first data packet - to be resent if the server doesn't ACK it. – Shane Madden Feb 23 '12 at 6:02
  • 1
    @Shane, that should be an answer. – Simon Richter Feb 23 '12 at 8:21

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.