Transport Layer & UDP
1. Transport Services & Protocols
The Transport Layer provides logical communication between application processes running on different hosts.
It runs only on the end systems (sender/receiver), not on network routers.
Sender: Breaks app messages into Segments, adds header.
Receiver: Reassembles segments, passes to app.
يعني إيه Logical Communication؟
يعني كأن البرنامجين (مثلاً Chrome و Web Server) متوصلين بسلك مباشر ببعض، مع إن في الحقيقة الداتا بتمشي في روترات وكابلات كتير جداً.
الفرق الجوهري: الـ Network Layer بتوصل "جواب" من بيت لبيت (Host-to-Host).
الـ Transport Layer بتوصل "الجواب" ده من باب البيت لحد إيد الشخص اللي عايشه جوه
(Process-to-Process).
2. Multiplexing & Demultiplexing
How does a computer handle multiple network apps (Chrome, Spotify, Zoom) at the same time?
The Socket
To identify a specific process, we need a Socket:
- Multiplexing (Sender): Gathering data from multiple sockets, enveloping each chunk with a header, and sending it out.
- Demultiplexing (Receiver): Looking at the Destination Port in the header to direct the segment to the correct socket.
مثال عملي (Multiplexing):
تخيل إنك "ساعي بريد" في شركة (الكمبيوتر). الشركة فيها موظفين كتير (Apps). كل موظف عايز يبعت جواب. إنت بتلم الجوابات دي كلها، وتحطها في شنطة واحدة (IP Datagrams) وتبعتها.
مثال عملي (Demultiplexing):
لما الجوابات ترجع، إنت بتبص على "الاسم" أو "رقم المكتب" (Port Number) عشان تدي كل موظف جوابه الخاص بيه، ماتديش جواب Zoom لـ Chrome بالغلط!
3. UDP (User Datagram Protocol) - Deep Dive
RFC 768. The definition of "No Frills". It does almost nothing other than multiplexing and error checking.
A. The UDP Header
Total Size: 8 Bytes only! (Very lightweight).
B. Why use UDP if it's "Unreliable"?
- No Connection Establishment: No RTT negotiation delay. Sends immediately. (Good for DNS).
- Simple: No connection state at sender/receiver. Server can handle more users.
- Small Header: 8 bytes overhead vs TCP's 20 bytes.
- No Congestion Control: It can blast data as fast as the link allows (Good for Real-time Streaming, even if packet loss occurs).
C. UDP Checksum (The Math)
Goal: Detect "flipped bits" (0 becomes 1 or vice versa) during transmission.
Step 1: Treat segment contents as sequence of 16-bit integers.
Step 2: Sum them up.
Step 3: If there's a "Carry" (Overflow), wrap it around and add it to the result.
Step 4: Take the 1's Complement (Flip all bits) to get Checksum.
1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
+ 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
---------------------------------
1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 (Sum has 17 bits!)
^
|___ WRAP AROUND (Add the Carry)
+ 1
---------------------------------
1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 (Final Sum)
0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 (Checksum: 1's Complement)
لا! ده حماية "ضعيفة" (Weak Protection). ممكن بتين يتغيروا بطريقة تخلي المجموع يطلع هو هو. بس هو بيصطاد الغلطات الشائعة.