1
votes

I was trying to understand how TCP works (not in detail of course). I was surfing the web for easy-to-understand flow diagrams and a question arose and couldn't find a straight answer.

Let's suppose that we have this nice flow where everything is sync (ignore the ending part with FIN and crossing packets):

enter image description here

I would like to know what would happen if both A and B would want to send packets at the same time (from what I understand TCP is a bidirectional protocol so each entity can send whenever it wants). Basically how the sequence numbers would behave. Having crossing data packets.

Also I read that TCP is a SWP (Sliding window protocol), I would like to know how ACKs are formed in this case. TCP is responding with number of bytes basically as Seq number, I can't really imagine how that can happen inside a window (where you can receive in any order). Is the implementation using two sets of seq numbers and two windows for both receiver and sender?

Any spec references or other helpful resources are more than welcome.

1
I don't think that the question is on-topic here. The spec you ask for is the standard - RFC 793. But basically TCP is a byte stream and the senders ACK specifies the current position in the senders byte stream (there is some initial offset - the initial sequence number in the handshake) and the ACK points out the last position the peers byte stream received. Window is unrelated to this.Steffen Ullrich
There is a separate sequence number in each direction.user207421

1 Answers

1
votes

I would like to know what would happen if both A and B would want to send packets at the same time (from what I understand TCP is a bidirectional protocol so each entity can send whenever it wants). Basically how the sequence numbers would behave. Having crossing data packets.

Each side in a TCP connection has its own sequence numbers. When side A sends bytes to side B, it increment its Sequence Number field, and side B increments its Acknowledgement field to signal which bytes were received. The opposite is true when side B sends data to side A - B's Sequence Number is incremented, and A's Acknowledgement. Both can happen simultaneously.

Also I read that TCP is a SWP (Sliding window protocol), I would like to know how ACKs are formed in this case. TCP is responding with number of bytes basically as Seq number, I can't really imagine how that can happen inside a window (where you can receive in any order). Is the implementation using two sets of seq numbers and two windows for both receiver and sender?

Yes. Both sides have their own independent sliding windows. Each side's send window is advanced according to the ACKs received from the other side, confirming the receipt of earlier sequence numbers.