Wednesday, July 2, 2008

TCP vs. UDP

TCP (Transmission Control Protocol) is one of the core protocols of the Internet protocol suite. TCP provides reliable, in-order delivery of a stream of bytes, making it suitable for applications like file transfer and e-mail. It is so important in the Internet protocol suite that sometimes the entire suite is referred to as "TCP/IP." TCP manages a large fraction of the individual conversations between Internet hosts, for example between web servers and web clients. It is also responsible for controlling the size and rate at which messages are exchanged between the server and the client.

TCP is used extensively by many of the Internet's most popular application protocols and resulting applications, including the World Wide Web, E-mail, File Transfer Protocol, Secure Shell, and some streaming media applications.

However, because TCP is optimized for accurate delivery rather than timely delivery, TCP sometimes incurs relatively long delays (in the order of seconds) while waiting for out-of-order messages or retransmissions of lost messages, and it is not particularly suitable for real-time applications such as Voice over IP. For such applications, protocols like the Real-time Transport Protocol (RTP) running over the User Datagram Protocol (UDP) are usually recommended instead.

TCP is a reliable stream delivery service that guarantees to deliver a stream of data sent from one host to another without duplication or losing data. Since packet transfer is not reliable, a technique known as positive acknowledgement with retransmission is used to guarantee reliability of packet transfers. This fundamental technique requires the receiver to respond with an acknowledgement message as it receives the data. The sender keeps a record of each packet it sends, and waits for acknowledgement before sending the next packet. The sender also keeps a timer from when the packet was sent, and retransmits a packet if the timer expires. The timer is needed in case a packet becomes lost or corrupt.

TCP (Transmission Control Protocol) consists of a set of rules, the protocol, that are used with the Internet Protocol, the IP, to send data “in a form of message units” between computers over the Internet. At the same time that the IP takes care of handling the actual delivery of the data, the TCP takes care of keeping track of the individual units of data “packets” that a message is divided into for efficient routing through the net. For example, when an HTML file is sent to you from a Web server, the TCP program layer of that server takes the file as a stream of bytes and divides it into packets, numbers the packets, and then forwards them individually to the IP program layer. Even though every packet has the same destination IP address, they can get routed differently through the network. When the client program in your computer gets them, the TCP stack (implementation) reassembles the individual packets and ensures they are correctly ordered as it streams them to an application.



UDP(User Datagram Protocol) does not guarantee reliability or ordering in the way that TCP does. Datagrams may arrive out of order, appear duplicated, or go missing without notice. Avoiding the overhead of checking whether every packet actually arrived makes UDP faster and more efficient, for applications that do not need guaranteed delivery. Time-sensitive applications often use UDP because dropped packets are preferable to delayed packets. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients. Unlike TCP, UDP is compatible with packet broadcast (sending to all on local network) and multicasting (send to all subscribers).

Common network applications that use UDP include: the Domain Name System (DNS), streaming media applications such as IPTV, Voice over IP (VoIP), Trivial File Transfer Protocol (TFTP) and online games.


Difference between TCP and UDP
TCP ("Transmission Control Protocol") is a connection-oriented protocol, which means that upon communication it requires handshaking to set up end-to-end connection. A connection can be made from client to server, and from then on any data can be sent along that connection.

* Reliable - TCP manages message acknowledgment, retransmission and timeout. Many attempts to reliably deliver the message are made. If it gets lost along the way, the server will re-request the lost part. In TCP, there's either no missing data, or, in case of multiple timeouts, the connection is dropped.
* Ordered - if two messages are sent along a connection, one after the other, the first message will reach the receiving application first. When data packets arrive in the wrong order, the TCP layer holds the later data until the earlier data can be rearranged and delivered to the application.
* Heavyweight - TCP requires three packets just to set up a socket, before any actual data can be sent. It handles connections, reliability and congestion control. It is a large transport protocol designed on top of IP.
* Streaming - Data is read as a "stream," with nothing distinguishing where one packet ends and another begins. Packets may be split or merged into bigger or smaller data streams arbitrarily.

UDP is a simpler message-based connectionless protocol. In connectionless protocols, there is no effort made to setup a dedicated end-to-end connection. Communication is achieved by transmitting information in one direction, from source to destination without checking to see if the destination is still there, or if it is prepared to receive the information. With UDP messages (packets) cross the network in independent units.

* Unreliable - When a message is sent, it cannot be known if it will reach its destination; it could get lost along the way. There is no concept of acknowledgment, retransmission and timeout.
* Not ordered - If two messages are sent to the same recipient, the order in which they arrive cannot be predicted.
* Lightweight - There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.
* Datagrams - Packets are sent individually and are guaranteed to be whole if they arrive. Packets have definite bounds and no split or merge into data streams may exist..

Tuesday, July 1, 2008

List of IP protocol numbers

0 - HOPOPT IPv6 Hop-by-Hop Option
1 - ICMP Internet Control Message Protocol
2 - IGMP Internet Group Management Protocol
3 - GGP Gateway-to-Gateway Protocol
4 - IP IP in IP (encapsulation)
5 - ST Internet Stream Protocol
6 - TCP Transmission Control Protocol
7 - CBT CBT
8 - EGP Exterior Gateway Protocol
9 - IGP Interior Gateway Protocol (any private interior gateway (used by Cisco for their IGRP))
10 - BBN-RCC-MON BBN RCC Monitoring
11 - NVP-II Network Voice Protocol
12 - PUP Xerox PUP
13 - ARGUS ARGUS
14 - EMCON EMCON
15 - XNET Cross Net Debugger
16 - CHAOS Chaos
17 - UDP User Datagram Protocol
18 - MUX Multiplexing
19 - DCN-MEAS DCN Measurement Subsystems
20 - HMP Host Monitoring Protocol
21 - PRM Packet Radio Measurement
22 - XNS-IDP XEROX NS IDP
23 - TRUNK-1 Trunk-1
24 - TRUNK-2 Trunk-2
25 - LEAF-1 Leaf-1
26 - LEAF-2 Leaf-2
27 - RDP Reliable Datagram Protocol
28 - IRTP Internet Reliable Transaction Protocol
29 - ISO-TP4 ISO Transport Protocol Class 4
30 - NETBLT Bulk Data Transfer Protocol
31 - MFE-NSP MFE Network Services Protocol
32 - MERIT-INP MERIT Internodal Protocol
33 - DCCP Datagram Congestion Control Protocol
34 - 3PC Third Party Connect Protocol
35 - IDPR Inter-Domain Policy Routing Protocol
36 - XTP XTP
37 - DDP Datagram Delivery Protocol
38 - IDPR-CMTP IDPR Control Message Transport Protocol
39 - TP++ TP++ Transport Protocol
40 - IL IL Transport Protocol
41 - IPv6 IPv6
42 - SDRP Source Demand Routing Protocol
43 - IPv6-Route Routing Header for IPv6
44 - IPv6-Frag Fragment Header for IPv6
45 - IDRP Inter-Domain Routing Protocol
46 - RSVP Resource Reservation Protocol
47 - GRE Generic Routing Encapsulation
48 - MHRP Mobile Host Routing Protocol
49 - BNA BNA
50 - ESP Encapsulating Security Payload
51 - AH Authentication Header
52 - I-NLSP Integrated Net Layer Security Protocol
53 - SWIPE IP with Encryption
54 - NARP NBMA Address Resolution Protocol
55 - MOBILE IP Mobility (Min Encap)
56 - TLSP Transport Layer Security Protocol (using Kryptonet key management)
57 - SKIP SKIP
58 - IPv6-ICMP ICMP for IPv6
59 - IPv6-NoNxt No Next Header for IPv6
60 - IPv6-Opts Destination Options for IPv6
61 - Any host internal protocol
62 - CFTP CFTP
63 - Any local network
64 - SAT-EXPAK SATNET and Backroom EXPAK
65 - KRYPTOLAN Kryptolan
66 - RVD MIT Remote Virtual Disk Protocol
67 - IPPC Internet Pluribus Packet Core
68 - Any distributed file system
69 - SAT-MON SATNET Monitoring
70 - VISA VISA Protocol
71 - IPCV Internet Packet Core Utility
72 - CPNX Computer Protocol Network Executive
73 - CPHB Computer Protocol Heart Beat
74 - WSN Wang Span Network
75 - PVP Packet Video Protocol
76 - BR-SAT-MON Backroom SATNET Monitoring
77 - SUN-ND SUN ND PROTOCOL-Temporary
78 - WB-MON WIDEBAND Monitoring
79 - WB-EXPAK WIDEBAND EXPAK
80 - ISO-IP International Organisation for Standardization Internet Protocol
81 - VMTP Versatile Message Transaction Protocol
82 - SECURE-VMTP Secure Versatile Message Transaction Protocol
83 - VINES VINES
84 - TTP TTP
85 - NSFNET-IGP NSFNET-IGP
86 - DGP Dissimilar Gateway Protocol
87 - TCF TCF
88 - EIGRP EIGRP
89 - OSPF Open Shortest Path First
90 - Sprite-RPC Sprite RPC Protocol
91 - LARP Locus Address Resolution Protocol
92 - MTP Multicast Transport Protocol
93 - AX.25 AX.25
94 - IPIP IP-within-IP Encapsulation Protocol
95 - MICP Mobile Internetworking Control Protocol
96 - SCC-SP Semaphore Communications Sec. Pro
97 - ETHERIP Ethernet-within-IP Encapsulation
98 - ENCAP Encapsulation Header
99 - Any private encryption scheme
100 - GMTP GMTP
101 - IFMP Ipsilon Flow Management Protocol
102 - PNNI PNNI over IP
103 - PIM Protocol Independent Multicast
104 - ARIS ARIS
105 - SCPS SCPS
106 - QNX QNX
107 - A/N Active Networks
108 - IPComp IP Payload Compression Protocol
109 - SNP Sitara Networks Protocol
110 - Compaq-Peer Compaq Peer Protocol
111 - IPX-in-IP IPX in IP
112 - VRRP Virtual Router Redundancy Protocol, Common Address Redundancy Protocol (not IANA assigned)
113 - PGM PGM Reliable Transport Protocol
114 - Any 0-hop protocol
115 - L2TP Layer Two Tunneling Protocol
116 - DDX D-II Data Exchange (DDX)
117 - IATP Interactive Agent Transfer Protocol
118 - STP Schedule Transfer Protocol
119 - SRP SpectraLink Radio Protocol
120 - UTI UTI
121 - SMP Simple Message Protocol
122 - SM SM
123 - PTP Performance Transparency Protocol
124 - IS-IS over IPv4
125 - FIRE
126 - CRTP Combat Radio Transport Protocol
127 - CRUDP Combat Radio User Datagram
128 - SSCOPMCE
129 - IPLT
130 - SPS Secure Packet Shield
131 - PIPE Private IP Encapsulation within IP
132 - SCTP Stream Control Transmission Protocol
133 - FC Fibre Channel
134 - RSVP-E2E-IGNORE
135 - Mobility Header
136 - UDP Lite
137 - MPLS-in-IP
138 - manet MANET Protocols
139 - HIP Host Identity Protocol