# 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

## TCP
### Packet Format

### Three-Way-Handshake

### Close Connection

### Flow Control
#### Stop and Wait
Send out the Packet, and wait for the Ack

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)