Packet and Frames
Packets
Packets are small pieces of data sent over internet protocol.
Why are we using packets?
Because data is exchanged in small pieces, the large messages don’t bottleneck the network. When sending packets over TCP, if packets are lost on their way, the server will send those packets aging instead of the whole message.
Packet header
Packets sent over internet protocol (IP) have additional pieces of information called headers.
Notable headers: Time to Live - expiry timer for the packet to not clog up your network. Checksum - Integrity checking, if any data in changed then the pack is corrupted. Source Address
- IP address of device that sent the packet.
- Destination Address - Destination IP address
TCP/IP protocol
TCP/IP protocol contains four layer:
- Application
- Transport
- Internet
- Network Interface
TCP is connection-based meaning it must establish a connection between both a client and a server before sending data. TCP guarantees that any data being sent will be received. This process is called Three-way handshake
explained in osi model
TCP packet headers:
- Source Port - port where TCP packet was sent. Chosen randomly.
- Destination Port - port where application or service is running on remote host.
- source ip - destination ip
- Sequence Number - first number is random
- Acknowledgement number - sequence number + 1
- Checksum - Integrity, like hash of file. If changed packet is corrupted.
- Data
- Flag - How packet should be handled during handshake. Specific flags will determine specific behaviour.
UDP/IP protocol
UDP connection is stateless.
UDP packet header
Same as TCP but no Sequence Number, Acknowledgement number, Checksum or Flag.
Three-way handshake
SYN ACK DATA FIN RST
Frames
Frames are a little like packets, but they don’t have IP addressing information. Frames contain the data, and they are sent inside packets.