Transport (TCP/UDP)
แนะนำใหม่ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| UDP/ˌjuː diː ˈpiː/ | โปรโตคอล UDP |
| TCP/ˌtiː siː ˈpiː/ | โปรโตคอล TCP |
| congestion control/kənˈdʒestʃn kənˈtrəʊl/ | slowing a sender down when the network is overloaded |
| three-way handshake/θriː weɪ ˈhændʃeɪk/ | การจับมือสามครั้ง |
| cumulative acknowledgement/ˈkjuːmjʊlətɪv əkˈnɒlɪdʒmənt/ | an ACK that confirms all bytes up to a given number |
| Flow control/fləʊ kənˈtrəʊl/ | slowing a sender so it does not overrun the receiver's buffer |
| congestion window/kənˈdʒestʃn ˈwɪndəʊ/ | the amount of unacknowledged data TCP lets itself send, set by congestion control |
| Slow start/sləʊ stɑːt/ | TCP's start-up phase, in which the congestion window doubles every round trip |
| duplicate ACKs/ˈdjuːplɪkeɪt ˌeɪ siː ˈkeɪz/ | repeated acknowledgements naming the same next byte, sent when segments arrive after a gap |
A postcard and a courier
- UDP 用户数据报协议 has an 8-byte header (ports, length, checksum), like a postcard. TCP 传输控制协议 adds sequence numbers, acknowledgements, retransmission, and flow and congestion control, like a courier who keeps a record book.
- The three-way handshake 三次握手 (SYN, SYN-ACK, ACK) opens a connection; FIN messages close it.

The UDP header carries —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
8 bytes: two ports, a length, a checksum - the postcard.
Put the opening of a TCP connection in order.
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Each side proposes its starting sequence number and has it acknowledged before data flows; that round trip is the price of TCP's guarantees.
The record book
- Using relative numbers (as Wireshark shows them; real connections start from a random number), the SYN uses sequence number 0 and the server's SYN-ACK carries its own 0.
- The client sends 100 bytes at seq 1, and the server ACKs 101. It sends 50 more at seq 101, and the ACK is 151.
- A 30-byte segment at seq 151 is lost. The cumulative acknowledgement 累积确认 stays at 151 until the timeout resends it, and then becomes 181. One ACK number sums up everything the receiver has.
After SYN (seq 0), 100 bytes then 50 sent, the server ACKs —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Cumulative: 1 + 100 + 50 = 151 - the next byte expected.
Choosing UDP
- A DNS request fits in one UDP datagram: one packet, and if it is lost the client asks again. Video calls can live with loss but not with delay: a resent frame that was due in 30 ms arrives too late to be useful.
- TCP guarantees order and delivery, but never speed. Flow control 流量控制 protects the receiver's buffer; congestion control 拥塞控制 protects the network. They are two different windows.
A live video call prefers —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Retransmitted frames arrive too late: tolerate loss, avoid delay.
The congestion window
- TCP sends at most one congestion window 拥塞窗口 per round trip (RTT). Slow start 慢启动 doubles it every RTT from $1$ segment: $1, 2, 4, 8, 16$. At the threshold it grows by one segment per RTT instead.
- A loss signalled by duplicate ACKs halves it, so the window draws a sawtooth; a timeout, a worse sign, drops it back to 1 segment.
- Throughput is about window over RTT: $20$ segments of $1460$ bytes per $50$ ms is $584$ KB/s, about $4.7$ Mb/s. Long, fast paths need large windows, which is why the window-scale option exists.
In slow start from a window of 1 segment, how many round trips until the window reaches 32 segments?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
1, 2, 4, 8, 16, 32: five doublings.
A window of 64 KB with a 100 ms round trip gives what throughput, in KB/s?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
64 KB per 0.1 s = 640 KB/s.
How long to wait before resending
- TCP keeps a smoothed round-trip estimate: new estimate $= 0.875 \times$ old $+ 0.125 \times$ sample. From 100 ms, a 140 ms sample gives $\mathbf{105}$ ms.
- The timeout is set a safety margin above that, and the margin grows when the samples vary more. Too short, and it resends packets that were only late; too long, and the line sits idle after a loss.
Smoothed RTT 100 ms, new sample 140 ms, weight 0.125: new estimate (ms)?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
$0.875 \times 100 + 0.125 \times 140 = 105$.
Worked example: fast retransmit
- Segments 1 to 6 are sent, and 3 is lost. The receiver acknowledges 2, then answers 4, 5 and 6 with the same "next expected is 3".
- Three duplicate ACKs 重复确认 tell the sender that 3 is missing while later data still arrives. It resends 3 at once, without waiting for the timeout, and halves its window instead of starting again from 1.
Segments of 1460 bytes needed in flight to fill 100 Mb/s at a 50 ms RTT (nearest whole)?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
$10^8 \times 0.05 / 8 = 625\,000$ bytes; $/1460 \approx 428$.
How many duplicate ACKs trigger fast retransmit?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Three duplicates mean later segments are arriving past a gap.
Marks that slip away
- The ACK as the last byte received. It names the next byte expected: after bytes $1$ to $100$ it is $101$.
- TCP for everything. A resent video frame arrives too late to show; UDP suits traffic that can lose packets but cannot wait.
- Mixing up flow and congestion control. Flow control protects the receiver's buffer; congestion control protects the network.
Recap
| UDP | TCP | |
|---|---|---|
| Header | 8 bytes | 20 bytes or more |
| Connection | none | handshake first |
| Delivery and order | not promised | promised |
| Use it for | DNS, video calls | web pages, files |
- The handshake is SYN, SYN-ACK, ACK; the cumulative ACK names the next byte expected.
- Flow control protects the receiver; congestion control protects the network.
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้