Translate

Thursday, 11 February 2016

Working of TCP and UDP

How TCP and UDP work?

A TCP connection is established via a three way handshake, which is a process of initiating and acknowledging a connection. Once the connection is established data transfer can begin. After transmission, the connection is terminated by closing of all established virtual circuits.

TCP PACKET FORMAT


TCP manages the flow of datagrams from the higher layers, as well as incoming datagrams from the IP layer. It has to ensure that priorities and security are respected. TCP must be capable of handling the termination of an application above it that was expecting incoming datagrams, as well as failures in the lower layers. TCP also must maintain a state table of all data streams in and out of the TCP layer. The isolation of these services in a separate layer enables applications to be designed without regard to flow control or message reliability. Without the TCP layer, each application would have to implement the services themselves, which is a waste of resources.

UDP uses a simple transmission model without implicit hand-shaking dialogues for guaranteeing reliability, ordering, or data integrity. Thus, UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without notice. UDP assumes that error checking and correction is either not necessary or performed in the application, avoiding the overhead of such processing at the network interface level. Unlike TCP, UDP is compatible with packet broadcasts (sending to all on local network) and multicasting (send to all subscribers).


UDP PACKET FORMAT



Why UDP is faster than TCP?

The reason UDP is faster than TCP is because there is no form of flow control. No error checking,error correction, or acknowledgment is done by UDP.UDP is only concerned with speed. So when, the data sent over the Internet is affected by collisions, and errors will be present.

UDP packet's called as user datagrams with 8 bytes header. A format of user datagrams is shown in figur 3. In the user datagrams first 8 bytes contains header information and the remaining bytes contains data.

Different Applications of TCP and UDP

Web browsing, email and file transfer are common applications that make use of TCP. 
TCP is used to control segment size, rate of data exchange, flow control and network congestion.
TCP is preferred where error correction facilities are required at network interface level. 
UDP is largely used by time sensitive applications as well as by servers that answer small queries from huge number of clients.
UDP is compatible with packet broadcast - sending to all on a network and multicasting  sending to all subscribers. 
UDP is commonly used in Domain Name System, Voice over IP, Trivial File Transfer Protocol and online games.

Need of TCP and UDP depends upon how data is required by sender
  • Use HTTP over TCP for making occasional, client-initiated stateless queries when it's OK to have an occasional delay.
  • Use persistent plain TCP sockets if both client and server independently send packets but an occasional delay is OK (e.g. Online Poker, many MMOs).
  • Use UDP if both client and server may independently send packets and occasional lag is not OK 

No comments:

Post a Comment