> For the complete documentation index, see [llms.txt](https://2ood.gitbook.io/2ood-knowledge-base/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://2ood.gitbook.io/2ood-knowledge-base/lecture-notes/networks/2023-10-05.md).

# 2023-10-05

> **Summary**

> **keywords**

> **TODO**

> **HW**

> **Exercise**\*

> **Next time**\
> TCP. and more about multiplexing with TCP.

***

## Recap

### video buffer

> currently on Streaming stored video. Chapter 7.2 on 6th ed.

In Video streaming, there's a TCP buffer, and Client buffer.\
\#read: analysis on video streaming

\#todo : paste image of buffer (with x, Q, R..)\
Startup delay : Q/x sec.\
where Q is the minimum byte client needs to start showing.\
x is the transmission rate (byte/ sec)

when R is bigger than x, and depletion rate is faster than x, there will be stopping in playing.\
when R is smaller than x, the buffer will be full, and there will be packet drop.

***

## Video Streaming (Cont'd)

### Manifest files

manifest file provides URLs for different chunks.\
manifest file is sent first. As the client manages the buffer, it chooses the right chunk needed.

***

## Socket programming w/ UDP & TCP

Steps (Application layer -> Transport layer)\
the running application is called a **process**.\
The process will create a socket with designated port.\
Done. All others are out of hand.

TCP will take care of the un-landed packets. (by ACK)\
UDP do not do connection establishment. UDP do not do a handshake.\
In UDP, sender explicitly attaches destination IP & port to each packet.

### Socket w/ UDP

#### Example app: UDP client

```python
from socket import *
serverName = 'hostname'
serverPort = 12000
clientSocket=socket(AF_INET,SOCK_DGRAM)

message=raw_input("input lower case sentance")
clientSocket.sendto(message.encode(),(serverName,serverPort)) #encodes string into bytes.

modifiedMessage, serverAddress = clientSocket.recvfrom(2048) # max byte to be recieved.
print modifiedMessage.decode() # utf-8 to string
clientSocket.clse()
```

#### Example server : UDP server

```python
from socket import *
serverPort = 12000

serverSocket=socket(AF_INET,SOCK_DGRAM)
serverSocket.bind(("",serverPort))
print("The server is ready to receive")

while True :
	message,clientAddress = serverSocket.recvfrom(2048)
	modifiedMessage - message.decode().upper()
	serverSocket.sendto(modifiedMessage.encode(),clientAddress)
```

### Socket w/TCP

* when client creates socket: client establishes connection to server TCP
  * difference : the `accept()` function is needed.
  * \#todo : check the process w/ wireshark.
* new socket for each client.

#### Example app : TCP client

```python
from socket import *
serverName = 'servername'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connet((serverName,serverPort))

```

\#todo : fill out the codes. both server and app.

#### Example server :TCP client

```python
...
while Ture:
	connectionSocket, addr = serverSocket.accept()

	sentence = connectionSocet.recv(1024).decode()
	capitalizedSentence = sentence.upper()
	connectionSocket.send(capitalizedSentence.encode())

	connectionSocket.close()
```
