A2.1.4

Describe the network protocols used for transport and application

Transmission Control Protocol (TCP) is a core protocol of the internet it operates at the transport layer(3rd layer) of the TCP/IP model TCP/IP Model:…

6 min read1,254 words
  • Transmission Control Protocol (TCP)
    • is a core protocol of the internet
    • it operates at the transport layer(3rd layer) of the TCP/IP model
      • TCP/IP Model: Application layer(forth layer), Transport layer(3rd layer), Internet layer(2nd layer), Network Interface layer(1st layer)
    • TCP provides reliable, ordered, and error-checked delivery of stream of bytes(packets) between hosts communicating via an IP network.
    • Key features
      • connection establishment
        • three-way handshake mechanism
          • Client → Server: SYN
            • “I want to establish a connection.”
            • (client sends initial sequence number)
          • Server → Client: SYN-ACK
            • “Connection accepted, I acknowledge your request.”
            • (acknowledges client + sends its own sequence number)
          • Client → Server: ACK
            • “Acknowledgement received. Connection established.”
      • data transfer with acknowledgement
        • TCP uses acknowledgements (ACKs) to confirm that data has been successfully received.

        • Each segment has a sequence number, this number must be acknowledged by the receiver.

        • how it works

          1. sender sends data with sequence number, for example, seq = 100
          2. receiver receives the data, then sends a ack, for example ack = 101
          3. This means: “I have received everything up to byte 100, send from 101 next.”
        • why is this important, it ensures:

          • reliability(prevent package loss)
            • ack won’t increase if there’s a package loss
            • sender detects the anomoly, then it will retransmit the data
          • ordered
            • packets/data may arrive out of order
            • TCP can reorder the packets based on the sequence number
            • then tranfers them to the Application layer
          • error detection
            • If corrupted(数据损坏):
              • no valid ACK
              • data is resent
      • flow control
  - sliding window 滑动窗口

  - receiver返还回去的ACK会带一个叫做window size的东西

    - `window size = 500 bytes`

    - this means that the receiver 最多还能接 500 字节

  - sender limits the amount of data transmit

    - cannot exceed the window size

    - otherwise there will result in overflow

  - receiver updates the window size

    - processed data successfully -> window size increases

    - or window size decreases

  - if `window size = 0`

    - receiver will terminate the data transmision

    - 然后等待窗口恢复

- **connection termination**

  - Four-way handshake mechanism

    - FIN (client -> server)

      - "I'm finished. All data has been transmitted."

      - send `FIN = 1`

    - ACK (server -> client)

      - "OK, i know you are going to terminate. "

      - send `ACK = 1`

    - FIN (server -> client)

      - "I'm also finished."

      - send `FIN = 1`

    - ACK(client -> server)

      - "OK, connection terminates formally."

      - send `ACK = 1`
  • User Datagram Protocal (UDP)
    • enables a connectionless mode of communication whereby data packets, or datagrams, are sent between devices without establishing or maintaining a stateful connection between the communication endpoints.
    • connectionless feature: faster, less-resource intensive then TCP, because it eliminates the overhead associated with setting up and maintaining a connection.
    • this feature is especially valuable in situation where occasional data loss/package loss is tolerable.
      • widely favoured for real-time application like video streaming, online gaming and VoIP.
      • in these cases, the priority is to reduce latency and to maintain continous flow of data, even some data packets arrive out of order
    • UDP also supports multicasting:
      • multicasting: the transmission of a packet to multiple destinations in a single send operation
      • making it suitable for applications such as live broadcasts and group collaborations
  • Hypertext Transfer Protocal (HTTP)
    • a foundational protocal for data communication over the World Wide Web(WWW).
    • 浏览器和服务器怎么说话的规则
      • open the browser, the browser sends a HTTP request
        • GET /index.html
      • the server receives the HTTP request, process it, then returns a HTTP response
        • Webpage content(HTML/CSS/JS)
        • status code
    • status code
HTTP Response CodeDescription
200 OKIndicates that the request has succeeded and the server has returned the expected content.
404 Not FoundThe server cannot find the requested resource. Often triggered by broken links or incorrect URL input.
500 Internal Server ErrorA generic error message indicating that the server encountered an unexpected condition that prevented it from fulfilling the request.
301 Moved PermanentlyThis response code is used when the requested resource has been permanently moved to a new URL, and any future references should use one of the returned URLs.
403 ForbiddenThe server understands the request but refuses to authorize it. This often occurs when access to the requested resource is restricted or denied.
- Request / Response Model

  - HTTP 采用请求-响应(request/response)模型:

    - Request(客户端 → 服务器)

      - Method(方法)

        - GET:获取资源

        - POST:提交数据

      - Headers(头部)

        - 元数据(如 content type、authentication)

      - Body(可选)

        - 发送的数据

    - Response(服务器 → 客户端)

      - Status Code(状态码)

        - 200 / 404 / 500 等

      - Headers(响应头)

      - Body(响应内容)

        - 网页 / 数据 / 错误信息

- HTTP 是一种 **stateless protocol(无状态协议)**

  - 每个请求都是独立的 **Each request is processed independently, as HTTP is a stateless protocol.**

  - 服务器不会记住之前的请求

  - 结果:

    - 无法自动识别用户身份

    - 无法保持登录状态或连续操作
  • 状态管理(State Management)
    • 由于 HTTP 无状态,需要额外机制来维护状态:
    • 🍪 Cookies(客户端)
      • 存储在浏览器中
      • 随请求自动发送到服务器
      • 用于保存:
        • 登录状态
        • 用户偏好
        • 浏览记录
    • 🧠 Sessions(服务器)
      • 存储在服务器端
      • 通过 Cookie 中的 session ID 识别用户
      • 用于:
        • 维护用户会话
        • 记录用户数据
  • Hypertext Transfer Protocal Secure (HTTPS)
    • is an extension of basic HTTP, specifically designed to enhance security for communications over the WWW.
    • HTTPS incorporates encryption into the data transmission process to protect the integrity and privacy of the data exchanged between a web server and a browser.
    • It can protect the confidentiality and integrity of the data.
    • Encryption Mechanism
      • HTTPS uses:
        • TLS (transport layer security)
        • SSL(deprecated)
      • how does it work:
        • encryption before sending the data
        • decryption after receiving the data
        • This ensures that even the data is being captured during the tramission process, the data is still unreadable.
    • Features of the URL
      • HTTPS uses https://, not http://
    • Why HTTPS is more secure?
      • it can prevent
        • eavesdropping(窃听)
        • tampering(篡改)
        • message forgery(伪造信息)
      • it can ensure the data during the transmission process
        • 不被读取
        • 不被修改
        • 来源可信(加密、解密)
> It **ensures confidentiality, integrity, and security against eavesdropping and tampering.**
  • Dynamic Host Configuration Protocal (DHCP)

    • DHCP automatically assigns IP addresses and other essential network configuration parameters to devices when they connect to a network.

    • Why DHCP?

      • 简化网络管理(no manual configuration)
      • 避免人工分配 IP 的:
        • 低效率 low efficiency
        • 易出错 human errors
    • How it works?

      • 设备连接网络时:
        • 发送 broadcast 请求
        • DHCP server:
          • 从地址池(address pool)分配 IP 地址
    • The DORA process

      1. Discover
        1. 客户端 → 广播(broadcast)
        2. 内容:“有没有 DHCP server?我需要 IP”
        3. 特点:没有 IP → 用广播, 发给整个网络
      2. Offer
        1. DHCP Server → 客户端
        2. 内容:
          1. 提供一个可用 IP
          2. 以及配置(subnet mask, gateway, DNS)
          3. 可以有多个 server 回复
      3. Request
        1. 客户端 → 广播
        2. 内容:
          1. “我要这个 IP(选中的那个)
          2. 同时告诉其他 server:“你们的我不要了”
      4. Acknowlgement (ACK)
        1. DHCP Server → 客户端
        2. 内容:
          1. 确认分配成功
          2. IP 正式生效
    • The information that DHCP offers:

      • IP address
      • subnet mask 子网掩码
      • Default gateway 默认网关
      • DNS server DNS解析服务器
    • Subnet Mask 子网掩码

      • determines the network segment the device is on
      • 32-bit 数字
      • 用于划分
        • 网络部分(network)
        • 主机部分(host)
      • 规则
        • 1 → network part
        • 0 → host part
      • for example:
        • 255.255.255.0
        • 二进制: 11111111.11111111.11111111.00000000
          • 前面的是network part,后面的是host part
    • Manners for allocating IP addresses

      • Dynamic Allocation
        • the IP address is lease(租用),代表temporary,临时的
        • 到期后需要重新申请
        • 用于
          • 临时设备:Laptop, phone
      • Static Allocation
        • IP address is fixed 地址是固定的
        • 根据 MAC address 分配
        • 常用于: printer, server
    • Advantages:

      • 防止 IP 冲突(address conflict)
      • 自动化配置
      • 提高网络效率
      • 适用于大型或动态网络
    • Disadvantages:

      • 单点故障(Single Point of Failure)
        • DHCP server寄了,所有新加入的设备,或是IP到期后的设备,就寄了,无法获取IP,无法连接网络
      • 安全问题 Security Issue
        • 可能出现 rogue DHCP server,假的DHCP服务器
          • 分配恶意/错误IP
          • man-in-the-middle attack 中间人攻击
      • 不适合需要固定IP的设备
      • 完成DORA可能需要时间,导致startup latency

    DHCP automatically assigns IP addresses and network settings to devices. It reduces manual configuration and prevents address conflicts.

Start typing to search all published objectives.