TRANSPORT CONTROL PROTOCOL (TCP)
TCP is a very clever design! One can quickly notice the ressemblance between TCP and a
coherent telephone conversation between two or more people.
The sender starts with "Hello. May I speak with Alex ?". The recipient replies "Sure.
May I ask
who's calling ?". And the sender answers "This is Peter". This 3 step process is how
TCP
initiates a transmission. A SYN packet including the sending address is sent, the recipient
answers with and acknowledge-syn packet (ACK SYN) including his address and the sender
acknowledge with an ACK packet. Note that the recipient answer "Yes. This is Alex speaking"
is not allowed since the sender has not identified himself at this point.
From here, the conversation can follow in both directions, provided that either one of the parties
has clearly understood what the other had to say. TCP does this through the Sequence (SEQ)
and Acknowledge (ACK) numbers. For simple explanatory purpose, every sent packet has a
SEQ number which is equal with the number of octets sent (and acknowledged to be received)
and an ACK number equal to the number of octets received up to the current packet. For the
receiver, these numbers reverse. If these numbers don't match the packet is re-transmitted or the
transmission stops in case the error cannot be corrected. Just as for a real conversation one part
can send a bulk of packets before receiving an acknowledge. And even more, "What did you
just say ?", "Can you say it again ?" or "Slow down a little, I can't follow"
are usual situations
implemented by TCP.
The conversation can finish with "Bye" followed by "OK, I'll talk to you later"
from the receiver
which in TCP terms it's called graceful. TCP implements a graceful end by sending a FIN packet
followed by a received ACK FIN packet. Or, the conversation may have a not-so-graceful end
when one part just hangs-up. In this case TCP sends a RST (reset) packet closing the
connection.
TCP is the protocol mostly utilized on the Internet. It's usually called TCP/IP because in all cases
TCP packets are encapsulated in IP packets.
TCP HEADER FORMAT
OCTET 1,2 Source Port(SRC_PORT)
OCTET 3,4 Destination Port(DEST_PORT)
OCTET 5,6,7,8 Sequence Number(SEQ)
OCTET 9,10,11,12 Acknowledgement Number(ACK)
OCTET 13,14 Data Offset (4 bit)+Reserved (6 bit)+
Control Flags (6 bit) (DTO, FLG)
OCTET 15,16 Window(WIN)
OCTET 17,18 Checksum(TCP_SUM)
OCTET 19,20 Urgent Pointer(URP)
OCTET 21,22,23 Options(OPT)
OCTET 24 Padding
OCTET 25,26
Data
TCP/IP Packet Example:
7E 21 45 00 00 4B 57 49 40 00 FA 06 85 77 C7 B6 78 0E CE D6 95 50 00 6E 04 9F 74 5B
EE A2 59 9A 00 0E 50 18 24 00 E3 2A 00 00 2B 4F 4B 20 50 61 73 73 77 6F 72 64 20 72
65 71 75 69 72 65 64 20 66 6F 72 20 61 6C 65 78 75 72 2E 0D 0A 67 B2 7E
Start 7E
SEP 21
IP Header 45 00 00 4B 57 49 40 00 FA 06 85 77 C7 B6 78 0E CE D6 95 50
TCP Header 00 6E 04 9F 74 5B EE A2 59 9A 00 0E 50 18 24 00 E3 2A 00 00
Data
2B 4F 4B 20 50 61 73 73 77 6F 72 64 20 72 65 71 75 69 72 65 64 20 66 6F 72 20 61 6C
65 78 75 72 2E 0D 0A
FCS 67 B2
Stop 7E
TCP Header:
SRC_PORT=110 DEST_PORT=1183 SEQ=745BEEA2 ACK=599A000E DTO=5
FLG=18 WIND=9216
TCP_SUM=E32A URP=0000 (No Options)
Data:
+OK Password required for alexur\r\n
Control Flags (FLG=18):
FLG=00011000 Urgent Pointer URG=0
Acknowledgment ACK=1
Push FunctionPSH=1
Reset connection RST=0
Synchronization SYN=0
Finished data FIN=0
State = ACK-PSH
|