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
-
TCP is a connection-oriented protocol, while UDP is a connectionless protocol.
-
TCP is a reliable protocol, while UDP is an unreliable protocol.
-
TCP is stateful, while UDP is stateless.
TCP Three-way Handshake
-
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
-
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)
-
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
-
Client send a
FIN
packet to the server. Means the client want to close the connection with the server. -
Server send a
ACK
packet to the client. Means the server receive the message client send. server comes toCLOSE_WAIT
state. -
Server send a
FIN
packet to the client. Means the server want to close the connection with the client. -
Client send a
ACK
packet to the server. Means the client receive the message server send. client comes toTIME_WAIT
state. (wait for 2MSL, if no message from the server, client will close the connection) If server do not receive theACK
packet, server will re-send theFIN
packet. 2MSL is to make sure the server receive theACK
packet.
As long as the four handshake do not finish, server and client can still send data