---
# System prepended metadata

title: Transport Layer
tags: [computer network]

---

# Transport Layer
###### tags: `computer network`
## Service in Transport Layer
* Connection Between Host and Host (Host may be different network)
In data link layer, it is responsible for connection of adjacnet macine, Note the difference
* Two Types of Service, Connectionless (UDP), Connection-Oriented (TCP)
## UDP
### When to Use UDP
* need recise control over error-control, flow control, timing, ...
* The real-time response is crucial (i.e. the delay must be minial even at the expense of losing small fraction of data), such as video chat
### Packet Format
![](https://i.imgur.com/gDPJaL6.png)
## TCP
### Packet Format
![](https://i.imgur.com/2YGNAe7.png)
### Three-Way-Handshake
![](https://i.imgur.com/9jaHAr3.png)
### Close Connection
![](https://i.imgur.com/h1mE4l0.png)

### Flow Control
#### Stop and Wait
Send out the Packet, and wait for the Ack
![](https://i.imgur.com/iK2lNER.png)
However, this method may suffer from
1. not in good use of bandwidth
2. Duplicate Data
3. Duplicate Ack

To resolve 2 and 3, we could add sequence number to it. To improve 1, we could use ***sliding windows***
#### Sliding Windows
Good reference video [here](https://www.youtube.com/watch?v=LnbvhoxHn8M&list=PLBlnK6fEyqRgMCUAG0XRw78UA8qnv6jEx&index=61&ab_channel=NesoAcademy)
