Question

I need to perform a 3way stop and wait handshake between client and server applications written in c++ (with winsock 2) for an assignment. The client sends a SYN. The server increments the client sequence number and sends a SYN-ACK. The client increments the server sequence number and sends an ACK.

To simulate packet loss, the client and server are connected to an intermediary Router program that occasionally does not forward packets, causing loss. How should I structure my sendto(), select(), recvfrom() statements to account for possible packet loss?

For example, if the SYN is lost and client times out, resend it. If the SYN-ACK is lost, client times out and resends SYN. I have no idea what to do if the ACK is lost though.

Edit: It basically goes like this on my client:

  • Send SYN.
  • Loop while select() statement fails and resend SYN
  • Receive SYN-ACK
  • Send ACK
  • Loop to possibly re-receive SYN-ACK if ACK was lost.

How do I know when to stop looping?

Was it helpful?

Solution

select can be used to check when a socket can be read from without blocking.

As for checking which sent packet the ACK belongs to, you check the sequence number.

If you don't receive an ACK within the timeout, you simple re-send the last packet. It doesn't matter what kind of packet you sent, if you don't receive an ACK you should resend it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top