Make delicious recipes!

Chapter 3: TCP vs UDP

Two main types of Transport Layer protocols

  1. TCP Service Model

  2. UDP Service Model


TCP Service Model

  1. Responsible for arranging the datagrams in sequence. TCP does this by adding sequence numbers before transmitting and then checking the same while assembling.

  2. Provides reliable communication by making sure all datagrams are received. If some datagrams are not received by TCP, it marks that communication as failed.

  3. Provides checksums to detect corrupt data.



TCP Header (Major Fields)

  1. Source Port

  2. Destination Port

  3. Sequence number

  4. Acknowledge sequence number (To let sender know which datagram has been correctly received).

  5. Checksum (Calculated over entire datagram including header and the data)

  6. A bunch of flags





3-way Handshake (makes TCP connection-oriented)



During the start of the connection, a 3-way handshake happens in TCP

This handshake is 3-way because TCP establishes 2 streams of communication: from client to server and from server to client.



To establish first stream, client sends a synchronize signal to server.

Server responds back by sending acknowledgement and synchronize signal back to client.

Client responds back by sending acknowledgement to server.



At the end of the communication, both client and server send finish signals to each other to signal the end of their respective streams. Both send an acknowledgement in return to this.







UDP Service Model


  1. Connectionless: UDP does not establish any connection as done by TCP

  2. Non-sequenced: Packets do not have any fixed sequence of arrival.

  3. No acknowledgements

  4. Checksum limited to header, not data

  5. Does not detect missing data


UDP Header (Major Fields)

  1. Source Port

  2. Destination Port

  3. Checksum (Calculated only over header and may optionally include data)

  4. A bunch of flags


ICMP (Internet Control Message Protocol) Service Model


ICMP was designed to be used as a diagnostic for the Internet but it serves a wider purpose.

Several applications use ICMP in interesting ways to gather network information. It sits above network layer and hence comes in parallel to TCP, UDP protocols (i.e. it comes in the Transport layer).


ICMP Types are defined as follows:

Type

Description

0

Echo reply (Used by ping)

1

 

2

 

3

Destination unreachable (Used by trace-route)

4

Source quench

5

Redirect

6

Alternate host address

7

 

8

Echo request (Used by ping)

9

Router advertisement

10

Router solicitation

11

Time exceeded

12

Parameter problem

13

Timestamp request

14

Timestamp reply

15

Information request. Not used anymore.

16

Information reply. Not used anymore.

17

Address mask request

18

Address mask reply

19

Reserved (for security)

20
-
29

Reserved (for robustness experiment).

30

Trace route

31

Conversion error

32

Mobile Host Redirect.

33

IPv6 ‘Where are you’.

34

IPv6 ‘I am here’.

35

Mobile registration request.

36

Mobile registration reply.

37

Domain name request.

38

Domain name reply.

39

SKIP Algorithm Discovery Protocol.

40

Security failures.

41

Experimental mobility protocols.

42
-
255

Reserved.


As can be seen from the above, these messages help to provide a control to the basic unreliable nature of the Internet transmission.

Some of the applications which make use of these ICMP messages are:


Ping

The application ‘ping’ is used to test whether a server is alive or not.

‘Ping’ sends an ICMP message with type ‘echo’

A server on receiving this request responds back with an ICMP message of type ‘echo response’.

Hence, if a server responds, then sender knows that the server is alive.


Trace-route

Trace-route is an application to trace the route from sender to receiver.

It works by sending a datagram first with a TTL of 1, then 2 and so on.

When datagram of TTL 1 expires, sender knows the information about first router.

When datagram of TTL 2 expires, information about second router is known and so on.

For the final receiver, sender puts in a destination port such that the receiver is bound to send an ‘Unrecognised port’ response.






Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal