Network - TCP/IP Model / HTTP

Contents

OSI VS TCP/IP

OSI stand for Open System Interconnection, which is a conceptual model. It is used to describe the functions of a networking system.

TCP/IP is a practicial implementation of the OSI model. It is a protocol stack used for communication over the internet.

OSI is conceptual and much complex, while TCP/IP is a practical model and is used widely.

TCP/IP

TCP/IP Model

TCP/IP is a protocol stack, which is a set of protocols that work together to provide communication functions. It is a four-layer model, which is a simplified version of the OSI model. These four layers are independent of each other, and each layer has its own protocols and functions. It is flexiable and decoupled.

TCP/IP Layers

  • Application Layer
  • Transport Layer
  • Internet Layer
  • Network Access Layer

1. Application Layer

Application layer is the top layer, it provide functionallity to exchange message between application programs and users. It defines the protocols and data formats used by application programs for exchanging messages.

HTTP, FTP, SMTP, DNS, SSH,, etc.

2. Transport Layer

Transport layer is responsible for end-to-end communication between two computers. It is responsible for breaking up the message into smaller packets and re-assembling the packets into the original message.

It use TCP or UDP protocols.

TCP is a connection-oriented, reliable protocol. It is used for critical data transmission.

UDP is a connectionless, unreliable protocol. It is used for non-critical data transmission. like the video streaming.

3. Internet Layer

Internet layer is responsible for transmitting packets from one host to another host. It is responsible for routing the packets.

It use IP, ARP, NAT protocol.

ARP : translate IP address to MAC address.

NAT : translate private IP address to public IP address.

4. Network Access Layer

Network access layer is responsible for transmitting data between two computers on the same network. It is responsible for transmitting packets from one host to another host.

TCP VS UDP

  1. TCP is a connection-oriented protocol, while UDP is a connectionless protocol.

  2. TCP is a reliable protocol, while UDP is an unreliable protocol.

  3. TCP is stateful, while UDP is stateless.

TCP Three-way Handshake

  1. Client send a SYN packet to the server. Means the client want to establish a connection with the server.

    Client: know nothing about the server
    Server : Server can receive, client can send
    
  2. Server send a SYN-ACK packet to the client. Means the server agree to establish a connection with the client. (send SYN back is to let client make sure the server receive the message client send)

    Client: Client can send and receive, Server can send and receive
    Server: Server can receive, client can send (same as the first step)
    
  3. Client send a ACK packet to the server. Means the client agree to establish a connection with the server, and finish the three-way handshake.

    Client: Client can send and receive, Server can send and receive
    Server: Server can send and receive, client can send and receive
    

Goal: make sure the client and the server both can send and receive data.

TCP Four-way Handshake

  1. Client send a FIN packet to the server. Means the client want to close the connection with the server.

  2. Server send a ACK packet to the client. Means the server receive the message client send. server comes to CLOSE_WAIT state.

  3. Server send a FIN packet to the client. Means the server want to close the connection with the client.

  4. Client send a ACK packet to the server. Means the client receive the message server send. client comes to TIME_WAIT state. (wait for 2MSL, if no message from the server, client will close the connection) If server do not receive the ACK packet, server will re-send the FIN packet. 2MSL is to make sure the server receive the ACK packet.

As long as the four handshake do not finish, server and client can still send data

Contents