TCP/IP and UDP/IP
The Internet protocol (IP) suite centers on the two most common communication standards called TCP and UDP. TCP/IP and UDP/IP evolved in the 1970s as a means for connecting Local Area Networks. The TCP/IP communication model is viewed as having 4 or 5 layers, and is the predecessor to The OSI Model. This article describes the fundamental concepts of the TCP/IP and UDP/IP model.
TCP Transmission Control Protocol
In the five layer TCP/IP model, TCP and UDP are the two most common protocols in layer four — the Transport Layer. They are used to communication between the Application Layer (5) and the IP Layer (3).
The most common protocols in the five layer TCP/IP model:
Layer 5. Application - DHCP, DNS, FTP, HTTP, MIME, POP3, SMTP, SNMP, SSH…
Layer 4. Transport - TCP, UDP, …
Layer 3. Network - IPv4, IPv6, …
Layer 2. Data Link - Ethernet, FDDI, ATM, …
Layer 1. Physical - Ethernet, Modems, ISDN, …
For TCP (Transmission Control Protocol), applications open a socket and send a stream of 8-bit bytes. TCP segments the stream according to the maximum transmission unit (MTU) of the Data Link Layer. TCP gives each packet a sequence number and generates a checksum to ensure that all the packets can be identified and the data is not corrupted during transmission. The receiver sends an acknowledgement for each packet. If the acknowledgement is not received, TCP will timeout and resend.
TCP Three Phase Connection
Unlike UDP (User Datagram Protocol), TCP establishes a connection, transfers data, and terminates the connection using three and four-way handshakes. The three-way connection handshake (SYN-ACK-ACK) allows the client and server to establish the packet sequence number, and verify the connection in both directions. During data transfer, each packet is acknowledged by returning the number of the last packet successfully received. A simple 16-bit checksum (not a 32-bit CRC) is used to verify packet integrity. When a packet is not acknowledged the sender can interpret the condition of the network and use congestion control algorithms to alter the flow of data.
The receiver will respond with a TCP Window Size to inform the sender how large a packet to send. When the receiver sends a window size of zero (0), the sender will wait and start a persist timer. When the timer expires the sender will send a small packet and listen for the window size in the response, thereby maintaining a persistent connection.
The TCP window size has a range of 2 to 65,535 bytes. A TCP window scale option can increase the window size from 65,535 to 1 Gigabyte. Large windows increase the efficiency of high bandwidth networks.
TCP closes a connection using a 4-way handshake to ensure that neither the client or sever is left open.
TCP Port Address
In addition to the IP address, TCP uses port numbers to identify the type of connection. Port numbers can be in the range of 1 to 65535. Some port numbers have been assigned as part of the Internet Assigned Port Authority (IAPA). Other ports may be registered by particular applications, or used privately. A few common port assignments are:
FTP 21 TELNET 23 SMTP 25 HTTP 80
TCP Segment Structure
A TCP IPv4 segment has a header and data section. The head has 10 required fields, and 1 optional field
FIELD SIZE NAME 01 16 Source Port 02 16 Destination Port 03 32 Sequence Number 04 32 Acknowledgement Number 05 4 Data Offset (size of header in 32-bit words, usually 5) 06 4 Reserved 07 8 Flags 08 16 Window 09 16 Checksum 10 16 Urgent Pointer 11 32 Options (optional) 12 ... Data
UDP User Datagram Protocol
In contrast to TCP, UDP is better suited to sending shot messages known as datagrams. UDP is stateless, meaning that the server retains no information about the client.
Like TCP, UDP uses port addresses. Port 0 is reserved. Ports 1 to 1023 are for the operating system and require root access to gain a binding. Ports 1024 to 49151 are registered ports, and ports 49152 to 65535 are ephemeral, and can be temporarily assigned for use by the client and server.
A UDP packet header has four fields:
FIELD SIZE NAME 01 16 Source Port 02 16 Destination Port 03 16 Length 04 16 Checksum 05 ... Data
Some key network applications that use UDP include Domain Name System (DNS), Simple Network Management Protocol (SNMP), Dynamic Host Configuration Protocol (DHCP), and Routing Information Protocol (RIP).
Since the loss of packets is not detectable using UDP it is best suited in situation where data is broadcast, it is not desirable for the server to retain the state of the client, and a failure is acceptable in terms of the overall efficiency and speed gained.
References
http://en.wikipedia.org/wiki/Transmission_Control_Protocol
http://en.wikipedia.org/wiki/User_Datagram_Protocol

























