Chapterبەش 6 · Lectureوانە 6.1

TCP and UDPTCP و UDP

The transport layer's two protocols compared: TCP's reliable, ordered connection and UDP's light, connectionless datagrams; their headers, the checksum both carry, QUIC and HTTP/3 over UDP, DNS over both, VPN tunnels and LAN discovery over UDP, and which applications use which.

بەراوردی دوو : پەیوەندیی متمانەپێکراو و بە ڕیزی و سووک و ؛ سەردێڕەکانیان، ئەو هەردووکیان هەڵیدەگرن، و ⁦HTTP/3⁩ بە سەر ، بە سەر هەردووکیاندا، تونێلەکانی و دۆزینەوە لە بە سەر و کام کامیان بەکار دەهێنێت.

24 min read26 خولەک خوێندنەوە · 20 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Explain what TCP and UDP both do and what only TCP adds.
  • Compare their headers (20–60 bytes and 8 bytes) and name the fields.
  • Compute and check a one's-complement checksum.
  • Choose TCP or UDP for an application; explain QUIC, HTTP/3 and DNS over both, and why VPN tunnels and LAN discovery use UDP.
  • ڕوونی بکەیتەوە و هەردووکیان چی دەکەن و چی تەنیا زیادی دەکات.
  • سەردێڕەکانیان (⁦20–60⁩ و 8 ) بەراورد بکەیت و خانەکانیان ناو ببەیت.
  • بژمێریت و بیپشکنیت.
  • یان بۆ هەڵبژێریت؛ ، ⁦HTTP/3⁩ و بە سەر هەردووکیاندا ڕوون بکەیتەوە، هەروەها بۆچی تونێلەکانی و دۆزینەوە لە بەکار دەهێنن.

Two delivery services: TCP and UDPدوو خزمەتگوزاریی گەیاندن: TCP و UDP

In OSI layers 4 and 5 you met the transport layer: it carries data from a program on one host to a program on another. TCP/IP gives this layer two protocols, and every application uses one of them: TCP, the Transmission Control Protocol, and UDP, the User Datagram Protocol. This lesson compares them: what each one promises, their headers, the checksum both of them carry, and which applications use which.

لە چینەکانی 4 و 5ی OSI ناسی: لە بەرنامەیەکەوە لەسەر بۆ بەرنامەیەک لەسەر تر دەگوازێتەوە. دوو بەم چینە دەدات و هەموو یەکێکیان بەکار دەهێنێت: ⁦(Transmission Control Protocol)⁩ و ⁦(User Datagram Protocol)⁩. ئەم وانەیە بەراوردیان دەکات: هەریەکەیان چ بەڵێنێک دەدات، سەردێڕەکانیان، ئەو هەردووکیان هەڵیدەگرن و کام کامیان بەکار دەهێنێت.

Two cards. TCP is a registered letter: a connection is set up first, pieces are numbered and put back in order, a receipt (ACK) comes back, a lost piece is sent again, header 20 to 60 bytes. UDP is a postcard: no setup, every card travels on its own, no receipt comes back, nothing is sent again, header only 8 bytes. Bottom: both carry port numbers and a checksum; only TCP promises that everything arrives, in order.دوو کارت. TCP نامەیەکی تۆمارکراوە: سەرەتا پەیوەندییەک دادەمەزرێت، پارچەکان ژمارەدارن و بە ڕیز کۆ دەکرێنەوە، وەسڵێک (ACK) دەگەڕێتەوە، پارچەی ونبوو دووپاتە دەنێردرێتەوە، سەردێڕ 20 تا 60 بایت. UDP کارتپۆستاڵێکە: بێ ئامادەکاری، هەر کارتێک بە تەنیا دەڕوات، هیچ وەسڵێک ناگەڕێتەوە، هیچ شتێک دووپاتە نانێردرێتەوە، سەردێڕ تەنیا 8 بایت. لە خوارەوە: هەردووکیان ژمارەی پۆرت و پشکنینێکی کۆ هەڵدەگرن؛ تەنیا TCP بەڵێن دەدات هەموو شتێک بە ڕیز بگات.
A registered letter and a postcard: the same post office, two different promises.نامەی تۆمارکراو و کارتپۆستاڵ: هەمان پۆستخانە، دوو بەڵێنی جیاواز.CêIT
The post office in Erbilپۆستخانەی هەولێر

Send a registered letter and the post office records it, the receiver signs for it, and if it goes missing they search and send it again: that is TCP. Drop a postcard in the box and it simply goes; nobody tells you whether it arrived: that is UDP. Postcards are cheaper and quicker because nobody checks anything.

نامەیەکی تۆمارکراو بنێرە: پۆستخانە تۆماری دەکات، وەرگر واژۆی بۆ دەکات و ئەگەر ون بوو بەدوایدا دەگەڕێن و دووپاتە دەینێرنەوە: ئەمە . کارتپۆستاڵێک بخەرە سندووقەکەوە و هەر دەڕوات؛ کەس پێت ناڵێت گەیشت یان نا: ئەمە . کارتپۆستاڵ هەرزانتر و خێراترە چونکە کەس هیچ شتێک ناپشکنێت.

Where the analogy stops workingسنووری ئەم نموونەیە

A letter is not cut into numbered pieces, and the post office does not slow down when the roads are full; TCP does both. And a UDP datagram is not lost on purpose: it is lost only when a network is overloaded or broken.

نامە ناکرێتە پارچەی ژمارەدار و پۆستخانە کاتێک ڕێگاکان قەرەباڵغن خاو نابێتەوە؛ هەردووکیان دەکات. بە ئەنقەست ون نابێت: تەنیا کاتێک زۆر قەرەباڵغ یان تێکچوو بێت ون دەبێت.

What both do, and what only TCP addsئەوەی هەردووکیان دەیکەن و ئەوەی تەنیا TCP زیادی دەکات

Some sources call the transport layer “the heart of OSI”: everything above it depends on how well it moves the data. TCP and UDP both do three basic jobs. They multiplex: port numbers say which program each piece belongs to. They segment: the application's data is cut into pieces and every piece gets a header. And they detect errors with a checksum. TCP adds much more: it opens a connection, numbers the bytes, acknowledges what arrived, resends what was lost, delivers in order, controls the flow and the congestion, and finally closes the connection.

هەندێک سەرچاوە بە «دڵی OSI» ناو دەبەن: هەموو ئەوەی لە سەرویەتی پشت بەوە دەبەستێت کە چەند باش دەگوازێتەوە. و هەردووکیان سێ کاری بنەڕەتی دەکەن. دەکەن: ژمارەی دەڵێت هەر پارچەیەک هی کام بەرنامەیە. دەکەن: دەکرێتە پارچە و هەر پارچەیەک سەردێڕێک وەردەگرێت. هەروەها بە هەڵە دەدۆزنەوە. زۆر شتی تر زیاد دەکات: پەیوەندییەک دەکاتەوە، ژمارە دەکات، دان بەوەدا دەنێت کە گەیشتووە، ونبووەکان دووپاتە دەنێرێتەوە، بە ڕیز دەیانگەیەنێت، ڕەوت و قەرەباڵغی کۆنترۆڵ دەکات و لە کۆتاییدا پەیوەندییەکە دادەخات.

Left, a blue box: TCP and UDP both use port numbers to reach the right program (multiplexing), cut data into pieces (segments or datagrams) and use a checksum to find damage. Right, a green box: only TCP adds seven jobs — open the connection with the three-way handshake, sequence numbers and acknowledgements, resend what was lost, put the pieces back in order, flow control with the window, congestion control, and close the connection with FIN and ACK. Bottom: layer 4 runs only in the two end hosts; routers never open a segment.لای چەپ، چوارگۆشەیەکی شین: TCP و UDP هەردووکیان ژمارەی پۆرت بۆ گەیشتن بە بەرنامەی دروست بەکار دەهێنن (مەڵتیپلێکسکردن)، دراوە دەکەنە پارچە (بڕەکان یان داتاگرامەکان) و پشکنینی کۆ بۆ دۆزینەوەی تێکچوون بەکار دەهێنن. لای ڕاست، چوارگۆشەیەکی سەوز: تەنیا TCP حەوت کار زیاد دەکات — کردنەوەی پەیوەندی بە سێ ڕێی تەوقەکردن، ژمارەکانی زنجیرە و دانپێدانان، ناردنەوەی ونبووەکان، ڕیزکردنەوەی پارچەکان، کۆنترۆڵی ڕەوت بە قەبارەی پەنجەرە، کۆنترۆڵی قەرەباڵغی و داخستنی پەیوەندی بە FIN و ACK. لە خوارەوە: چینی 4 تەنیا لە دوو میوانگرەکەی سەرەتا و کۆتاییدا کار دەکات؛ ڕێدۆزەکان هەرگیز بڕێک ناکەنەوە.
Three jobs are shared; the rest is TCP's extra work.سێ کار هاوبەشن؛ ئەوانی تر کاری زیادەی .CêIT

How TCP opens, manages and closes a connection is the subject of Inside a TCP connection; port numbers are in Port numbers and sockets.

چۆن پەیوەندییەک دەکاتەوە، بەڕێوەی دەبات و دایدەخات، بابەتی ناو پەیوەندییەکی TCPـە؛ ژمارەی لە وانەی ژمارەی پۆرت و سۆکێتەکان باس کراون.

What both do, and what only TCP addsئەوەی هەردووکیان دەیکەن و ئەوەی تەنیا TCP زیادی دەکات

How big is one segment?بڕێک چەند گەورەیە؟

Segmentation lets a host send a file of any size over any network: the transport layer decides how much data goes into each piece. On Ethernet a frame carries at most 1,500 bytes of payload (the MTU); the IP header and the TCP header take 20 bytes each, so one TCP segment carries up to 1,460 bytes of data. This number is the maximum segment size (MSS), and the two hosts tell each other theirs when the connection opens. The size depends on the link, not on the speed: a faster line sends the same segments in less time.

وا دەکات بتوانێت بە هەر قەبارەیەک بە سەر هەر بنێرێت: بڕیار دەدات چەند بچێتە ناو هەر پارچەیەکەوە. لەسەر Ethernet ئەوپەڕی ⁦1,500⁩ هەڵدەگرێت ()؛ سەردێڕی و سەردێڕی هەریەکەیان ⁦20⁩ دەگرن، بۆیە تا ⁦1,460⁩ هەڵدەگرێت. ئەم ژمارەیە گەورەترین قەبارەی ⁦(MSS)⁩ـە و دوو لە کاتی کردنەوەی پەیوەندیدا هی خۆیان بە یەکتر دەڵێن. قەبارەکە بەندە بە بەستەرەکە، نەک بە خێرایی: هێڵێکی خێراتر هەمان لە کاتێکی کەمتردا دەنێرێت.

An Ethernet frame of 1,500 bytes: 20 bytes of IP header, 20 bytes of TCP header and up to 1,460 bytes of data, the MSS. Below: a 100-megabit file is 12,500,000 bytes; 12,500,000 ÷ 1,460 = 8,561 full segments plus 940 bytes, so 8,562 segments. The bandwidth changes how long it takes, not the size of a segment.فرەیمێکی Ethernet بە 1,500 بایت: 20 بایت سەردێڕی IP، 20 بایت سەردێڕی TCP و تا 1,460 بایت دراوە، واتە MSS. لە خوارەوە: فایلێکی 100 Mbit دەکاتە 12,500,000 بایت؛ 12,500,000 ÷ 1,460 = 8,561 بڕی پڕ و 940 بایت، کەواتە 8,562 بڕ. پانایی باند کاتی ناردن دەگۆڕێت، نەک قەبارەی بڕ.
1,500 = 20 + 20 + 1,460: the data in one full segment.⁦1,500 = 20 + 20 + 1,460⁩: یەک پڕ.CêIT
12 500 000 bytes1 460 bytes per segment≈8 561.6  ⇒  8 562 segments\frac{12\,500\,000\ \text{bytes}}{1\,460\ \text{bytes per segment}} \approx 8\,561.6 \;\Rightarrow\; 8\,562\ \text{segments}

A 100-megabit file needs 8,561 full segments and one last segment of 940 bytes. At 1 Mbit/s it takes at least 100 seconds, at 100 Mbit/s about one second — with exactly the same segments.

⁦100 Mbit⁩ پێویستی بە ⁦8,561⁩ پڕ و دوایین بە ⁦940⁩ هەیە. بە ⁦1 Mbit/s⁩ لانیکەم ⁦100⁩ چرکەی دەوێت، بە ⁦100 Mbit/s⁩ نزیکەی یەک چرکە — بە ڕێک هەمان .

The pieces of one message may travel by different routes and arrive out of order; the receiving transport layer puts them back together. That is reassembly — OSI layers 4 and 5 shows it as an animation.

پارچەکانی یەک نامە ڕەنگە بە ڕێگای جیاوازدا بڕۆن و بە ڕیزی جیاواز بگەن؛ وەرگر دووپاتە پێکەوەیان دەنێتەوە. ئەمە کۆکردنەوەیە — چینەکانی 4 و 5ی OSI بە ئەنیمەیشن پیشانی دەدات.

Different applications, different needsئەپەکانی جیاواز، پێویستیی جیاواز

Why two protocols? Because applications need different things. A voice call or a live video needs speed and little overhead: no waiting for acknowledgements and no resending, because a piece that arrives late is useless — deliver each piece as it arrives. E-mail, web pages and file downloads need the opposite: every byte acknowledged, lost data sent again, everything in the order it was sent. The application developer picks the transport protocol that fits the application; the user never chooses.

بۆچی دوو ؟ چونکە پێویستییان بە شتی جیاوازە. پەیوەندییەکی دەنگی یان ڤیدیۆیەکی ڕاستەوخۆ پێویستی بە خێرایی و بارگرانیی کەمە: چاوەڕێی نەکات و هیچ دووپاتە نەنێرێتەوە، چونکە پارچەیەک کە درەنگ بگات بێسوودە — هەر پارچەیەک هەرکاتێک گەیشت بیگەیەنە. ، و پێچەوانەکەیان دەوێت: دان بە هەموو بنرێت، ونبوو دووپاتە بنێردرێتەوە و هەموو شتێک بە ڕیزی ناردن بگات. گەشەپێدەری ئەو گواستنەوەیە هەڵدەبژێرێت کە لەگەڵ دەگونجێت؛ بەکارهێنەر هەرگیز هەڵی نابژێرێت.

Left, an orange list for voice calls and live video: fast, low overhead, no acknowledgements, do not resend lost data, deliver as it arrives; an arrow points to UDP. Right, a green list for e-mail, web pages and files: reliable, acknowledge the data, resend lost data, deliver in the order sent, no missing byte; an arrow points to TCP. In the middle, a stack: application, transport (UDP and TCP side by side), Internet (IP). The developer picks the transport protocol. No protocol is best: each one is right for some applications.لای چەپ، لیستێکی پرتەقاڵی بۆ پەیوەندیی دەنگی و ڤیدیۆی ڕاستەوخۆ: خێرا، بارگرانیی کەم، بێ دانپێدانان، ونبوو دووپاتە مەنێرەوە، هەرچۆن گەیشت بیگەیەنە؛ تیرێک بەرەو UDP. لای ڕاست، لیستێکی سەوز بۆ ئیمەیڵ، لاپەڕەتۆڕەکان و فایلەکان: متمانەپێکراو، دانپێدانان بە دراوەدا، ونبوو دووپاتە بنێرەوە، بە ڕیزی ناردن بیگەیەنە، هیچ بایتێک کەم نەبێت؛ تیرێک بەرەو TCP. لە ناوەڕاستدا ستوونێک: ئەپ، گواستنەوە (UDP و TCP لە تەنیشت یەک)، ئینتەرنێت (IP). گەشەپێدەر پرۆتۆکۆڵی گواستنەوە هەڵدەبژێرێت. هیچ پرۆتۆکۆڵێک باشترین نییە: هەریەکەیان بۆ هەندێک ئەپ گونجاوە.
Two lists of needs, two protocols.دوو لیستی پێویستی، دوو .CêIT

TCP: connection-oriented and reliableTCP: گرێدانتەوەر و متمانەپێکراو

TCP is connection-oriented: before any data moves, the two hosts set up a connection with the three-way handshake, and everything TCP does is built around that connection — the way Java is called object-oriented because everything is built around objects. TCP, which almost every system has, then does its best to deliver every byte, without errors and in order. A TCP connection is full duplex: once it is open, both sides can send at the same time, like two friends typing in the same chat. Web browsing up to HTTP/2, e-mail (SMTP, IMAP, POP3), FTP, SSH and speed-test sites — which open several TCP connections at once — all use TCP.

: پێش ئەوەی هیچ بجووڵێت، دوو بە پەیوەندییەک دادەمەزرێنن و هەموو کارێکی لە دەوری ئەو پەیوەندییە دروست کراوە — وەک چۆن بە جاڤا دەڵێن ئۆبجێکتتەوەر، چونکە هەموو شتێکی لە دەوری ئۆبجێکت دروست کراوە. پاشان ، کە لە نزیکەی هەموو سیستەمێکدا هەیە، هەموو هەوڵێک دەدات هەموو بێ هەڵە و بە ڕیز بگەیەنێت. پەیوەندیی : کە کرایەوە، هەردوو لا دەتوانن لە هەمان کاتدا بنێرن، وەک دوو هاوڕێ کە لە هەمان چاتدا پێکەوە دەنووسن. گەڕان لە وێب تا ⁦HTTP/2⁩، (، ، )، ، و ماڵپەڕەکانی پشکنینی خێرایی — کە لە یەک کاتدا چەند پەیوەندییەکی دەکەنەوە — هەموویان بەکار دەهێنن.

Aram's laptop in Duhok (192.0.2.10, port 51234) and a chat server in Erbil (203.0.113.5, port 443) joined by one TCP connection drawn as a pipe with two lanes. On the top lane Aram's messages 1, 2 and 3 travel to the server; on the bottom lane Shilan's messages and the acknowledgements travel back at the same time. Full duplex: like two friends typing in a chat at the same time; each side numbers its own bytes and acknowledges the other side's bytes.لاپتۆپی ئارام لە دهۆک (192.0.2.10، پۆرتی 51234) و ڕاژەکارێکی چات لە هەولێر (203.0.113.5، پۆرتی 443)، بە یەک پەیوەندیی TCP بەیەکەوە بەستراون کە وەک بۆرییەکی دوو ڕێڕەو کێشراوە. لە ڕێڕەوی سەرەوە نامەکانی 1، 2 و 3ی ئارام بەرەو ڕاژەکار دەچن؛ لە ڕێڕەوی خوارەوە نامەکانی شیلان و ACKـەکان لە هەمان کاتدا دەگەڕێنەوە. دوولایەنەی هاوکات: وەک دوو هاوڕێ کە لە هەمان کاتدا لە چاتێکدا دەنووسن؛ هەر لایەک بایتەکانی خۆی ژمارە دەکات و دان بە بایتەکانی لایەکەی تردا دەنێت.
One connection, two directions at the same time.یەک پەیوەندی، دوو ئاڕاستە لە هەمان کاتدا.CêIT

UDP: connectionless and lightUDP: بێ‌گرێدان و سووک

UDP is connectionless: there is no handshake and no connection. Each datagram is sent on its own and handled independently, like a postcard. UDP adds very little to IP — ports, a length and a checksum — so its header is only 8 bytes and nothing waits or is resent. That makes UDP unreliable in the technical sense: it does not guarantee delivery or order. It does not make the application unreliable. A DNS client simply asks again when no answer comes, and a call or a game can live with a missing piece. Key users of UDP: DNS, DHCP, SNMP, TFTP, RIP, voice and video calls (RTP), online games — and, since HTTP/3, much web traffic.

: نە هەیە و نە پەیوەندی. هەر بە تەنیا دەنێردرێت و بە سەربەخۆیی مامەڵەی لەگەڵ دەکرێت، وەک کارتپۆستاڵێک. شتێکی زۆر کەم بۆ زیاد دەکات — ، درێژی و — بۆیە سەردێڕەکەی تەنیا 8 و هیچ شتێک چاوەڕێ ناکات یان دووپاتە نانێردرێتەوە. ئەمە بە واتا تەکنیکییەکەی نامتمانەپێکراو دەکات: گەیاندن و ڕیز مسۆگەر ناکات. بەڵام نامتمانەپێکراو ناکات. کاتێک وەڵام نایەت تەنیا دووپاتە دەپرسێتەوە و پەیوەندییەکی دەنگی یان یارییەک دەتوانێت لەگەڵ پارچەیەکی ونبوودا بژی. بەکارهێنەرە سەرەکییەکانی : ، ، SNMP، ، ، پەیوەندیی دەنگی و ڤیدیۆیی ⁦(RTP)⁩، یاریی ئۆنلاین — و لە ⁦HTTP/3⁩ـەوە بەشێکی زۆری هاتوچۆی وێب.

Hana's phone asks a DNS server for www.example.com over UDP port 53. The query is lost on the way (a red cross). A clock shows that no answer came before the timer ended, so the app sends the same query again; this time the answer 192.0.2.80 comes back. Bottom: one tiny question and one tiny answer — asking again is cheaper than opening a TCP connection; the reliability comes from the application, not from UDP.مۆبایلی هانا بە UDP و پۆرتی 53 لە ڕاژەکارێکی DNS دەپرسێت www.example.com چییە. پرسیارەکە لە ڕێگادا ون دەبێت (خاچێکی سوور). کاتژمێرێک پیشان دەدات کە پێش کۆتایی تایمەرەکە هیچ وەڵامێک نەهات، بۆیە ئەپەکە هەمان پرسیار دووپاتە دەنێرێتەوە؛ ئەمجارە وەڵامی 192.0.2.80 دەگەڕێتەوە. لە خوارەوە: پرسیارێکی بچووک و وەڵامێکی بچووک — دووپاتە پرسینەوە هەرزانترە لە کردنەوەی پەیوەندییەکی TCP؛ پشتپێبەستراوی لە ئەپەکەوە دێت، نەک لە UDPـەوە.
The application, not UDP, asks again. دووپاتە دەپرسێتەوە، نەک .CêIT

When a piece is lostکاتێک پارچەیەک ون دەبێت

Here is the real difference. A server sends Aram a PDF with TCP while Shilan makes a video call from Erbil to Duhok over UDP. On both roads piece 3 is lost. TCP's receiver keeps pieces 4 and 5 in its buffer and asks for 3 again; the sender resends it, and the file is complete and in order — a little later. The video call cannot wait: the app shows what it has, the picture glitches for a moment, and the call goes on with pieces 6 and 7.

جیاوازییە ڕاستەقینەکە ئەمەیە. بە PDFێک بۆ ئارام دەنێرێت، لە کاتێکدا شیلان بە پەیوەندییەکی ڤیدیۆیی لە هەولێرەوە بۆ دهۆک دەکات. لە هەردوو ڕێگاکەدا پارچەی 3 ون دەبێت. وەرگری پارچەکانی 4 و 5 لە دەهێڵێتەوە و دووپاتە داوای 3 دەکات؛ نێرەر دووپاتەی دەنێرێتەوە و تەواو و بە ڕیز دەگات — کەمێک دواتر. پەیوەندییە ڤیدیۆییەکە ناتوانێت چاوەڕێ بکات: ئەوەی هەیەتی پیشانی دەدات، وێنەکە ساتێک دەپچڕێت و پەیوەندییەکە بە پارچەکانی 6 و 7 بەردەوام دەبێت.

Animation in five steps with two lanes. Top lane, TCP: a server sends pieces 1 to 5 of a PDF file to a phone. Bottom lane, UDP: a video call from Erbil to Duhok sends pieces 1 to 5. Piece 3 is lost on both lanes. TCP's receiver holds 4 and 5 in its buffer and sends back “ACK 3: I still need 3”; the sender sends piece 3 again and the receiver ends with 1 2 3 4 5 complete. UDP's receiver shows 1, 2, 4 and 5 at once with a short glitch, while 6 and 7 are already on the way, and keeps an empty slot where 3 should be. Last frame: TCP is complete and in order, a little later; UDP is on time, with an empty slot.
Animation in five steps with two lanes. Top lane, TCP: a server sends pieces 1 to 5 of a PDF file to a phone. Bottom lane, UDP: a video call from Erbil to Duhok sends pieces 1 to 5. Piece 3 is lost on both lanes. TCP's receiver holds 4 and 5 in its buffer and sends back “ACK 3: I still need 3”; the sender sends piece 3 again and the receiver ends with 1 2 3 4 5 complete. UDP's receiver shows 1, 2, 4 and 5 at once with a short glitch, while 6 and 7 are already on the way, and keeps an empty slot where 3 should be. Last frame: TCP is complete and in order, a little later; UDP is on time, with an empty slot.
TCP trades time for completeness; UDP trades completeness for time. کات دەدات بۆ تەواوی؛ تەواوی دەدات بۆ کات.CêIT

TCP is not “slow”: on a good network it is very fast. It waits only for the handshake at the start and when something is lost.

«خاو» نییە: لەسەر باش زۆر خێرایە. تەنیا بۆ لە سەرەتادا و کاتێک شتێک ون دەبێت چاوەڕێ دەکات.

Two headers: 20 bytes and 8 bytesدوو سەردێڕ: ⁦20⁩ بایت و 8 بایت

Every segment and every datagram starts with a header. Both headers begin with the source port and the destination port, 16 bits each, and both carry a 16-bit checksum. The UDP header adds only a length field: 8 bytes in all. The TCP header is at least 20 bytes: it also carries the sequence number, the acknowledgement number, the header length (data offset), the flags, the window and the urgent pointer. Options can make it up to 60 bytes, because the data offset counts the header in 4-byte words, from 5 (20 bytes) to 15 (60 bytes).

هەموو و هەموو بە سەردێڕێک دەست پێ دەکات. هەردوو سەردێڕەکە بە سەرچاوە و مەبەست دەست پێ دەکەن، هەریەکەیان ⁦16⁩ . هەروەها هەردووکیان ⁦16⁩ هەڵدەگرن. سەردێڕی تەنیا خانەیەکی درێژی زیاد دەکات: سەرجەم 8 . سەردێڕی لانیکەم ⁦20⁩ : ، ژمارەی ، درێژیی سەردێڕ (data offset)، ئاڵاکان، و نیشاندەری بەپەلەش هەڵدەگرێت. هەڵبژاردەکان دەتوانن بیکەنە تا ⁦60⁩ ، چونکە data offset سەردێڕەکە بە وشەی 4 دەژمێرێت، لە 5 وشە (⁦20⁩ ) تا ⁦15⁩ وشە (⁦60⁩ ).

The TCP header and the UDP header drawn to the same scale, 32 bits per row. TCP: source port and destination port; sequence number; acknowledgement number; offset, reserved, flags and window; checksum and urgent pointer; then options of 0 to 40 bytes — 20 bytes without options, up to 60 bytes. The flags are CWR, ECE, URG, ACK, PSH, RST, SYN and FIN, one bit each. UDP: source port and destination port; length and checksum — 8 bytes. The ports and the checksum, coloured green, are in both headers.سەردێڕی TCP و سەردێڕی UDP بە هەمان پێوەر، هەر ڕیزێک 32 بیت. TCP: پۆرتی سەرچاوە و پۆرتی مەبەست؛ ژمارەی زنجیرە؛ ژمارەی دانپێدانان؛ درێژی، پارێزراو، ئاڵاکان و قەبارەی پەنجەرە؛ پشکنینی کۆ و نیشاندەری بەپەلە؛ پاشان هەڵبژاردەکان لە 0 تا 40 بایت — بێ هەڵبژاردە 20 بایت، تا 60 بایت. ئاڵاکان CWR، ECE، URG، ACK، PSH، RST، SYN و FINن، هەریەکەیان یەک بیت. UDP: پۆرتی سەرچاوە و پۆرتی مەبەست؛ درێژی و پشکنینی کۆ — 8 بایت. پۆرتەکان و پشکنینی کۆ، بە ڕەنگی سەوز، لە هەردوو سەردێڕەکەدان.
TCP's header is at least 20 bytes; UDP's is always 8.سەردێڕی لانیکەم ⁦20⁩ ؛ هی هەمیشە 8.CêIT

Two headers: 20 bytes and 8 bytesدوو سەردێڕ: ⁦20⁩ بایت و 8 بایت

What each TCP field is forهەر خانەیەکی TCP بۆ چییە

The TCP header (RFC 9293). UDP has only the two ports, a length and a checksum.سەردێڕی ⁦(RFC 9293)⁩. تەنیا دوو ، درێژی و هەیە.
FieldخانەSizeقەبارەWhat it is forبۆ چییە
Source port سەرچاوە16 bitThe sending programبەرنامەی نێرەر
Destination port مەبەست16 bitThe receiving programبەرنامەی وەرگر
Sequence number32 bitThe number of the first data byte in this segmentژمارەی یەکەم لەم
Acknowledgement numberژمارەی 32 bitThe next byte this side expects from the other side (valid when ACK is set) داهاتوو کە ئەم لایە چاوەڕێی دەکات (کاتێک ACK دانرابێت)
Data offsetData offset (درێژیی سەردێڕ)4 bitHeader length in 4-byte words: 5 to 15درێژیی سەردێڕ بە وشەی 4 : 5 تا ⁦15⁩
Reservedپارێزراو4 bitKept for the future; sent as 0بۆ داهاتوو هەڵگیراوە؛ وەک 0 دەنێردرێت
Flagsئاڵاکان8 × 1 bitCWR and ECE (congestion signals), URG, ACK, PSH, RST, SYN, FIN — see control bitsCWR و ECE (ئاماژەی قەرەباڵغی)، URG، ACK، PSH، RST، SYN، FIN — بڕوانە بیتەکانی کۆنترۆڵ
Window (window size)16 bitHow many bytes the receiver can take nowوەرگر ئێستا چەند وەردەگرێت
Checksum16 bitError detection over the header, the data and the IP addressesدۆزینەوەی هەڵە لە سەردێڕ، و
Urgent pointerنیشاندەری بەپەلە16 bitMarks urgent data; rarely used today بەپەلە دیاری دەکات؛ ئەمڕۆ کەم بەکار دێت
Optionsهەڵبژاردەکان0–40 bytes⁦0–40⁩ For example the MSS, window scaling and timestampsبۆ نموونە MSS، گەورەکردنی و

Segment, datagram, packet: the right wordsبڕ، داتاگرام، پاکێت: وشە دروستەکان

Each layer has its own name for its unit of data. TCP's unit is a segment; UDP's unit is a datagram; the IP layer puts either of them inside a packet; and the link layer puts the packet inside a frame. You will sometimes read “packet” for TCP data and “datagram” for UDP data, with the idea that a datagram is a piece with no guarantee. Keep the exact words: segment (TCP), datagram (UDP), packet (IP). The full ladder of names is in PDUs.

هەر چینێک ناوێکی تایبەتی بۆ یەکەی خۆی هەیە. یەکەی ؛ یەکەی ؛ چینی هەر کامیان بێت دەیخاتە ناو ؛ و چینی بەستەر دەخاتە ناو . هەندێک جار دەخوێنیتەوە کە «» بۆ و «» بۆ بەکار دێت، بەو بیرۆکەیەی کە پارچەیەکی بێ گەرەنتییە. وشە ورددەکان بەکار بهێنە: ()، ()، (). هەموو پەیژەی ناوەکان لە یەکەکانی دراوەی پرۆتۆکۆڵدایە.

Two nested drawings. Top: a frame (frame header and trailer) holds an IP packet (blue), which holds a TCP segment (green): a TCP header and application data, for example part of a web page. Bottom: the same with a UDP datagram (orange): a UDP header and application data. Text: the IP packet carries the segment or the datagram, and the frame carries the packet. Wrong: “TCP sends packets, UDP sends datagrams”; TCP sends segments and IP sends packets.دوو وێنەی یەک لە ناو یەک. سەرەوە: فرەیمێک (سەردێڕی فرەیم و پاشکۆ) پاکێتێکی IP (شین) هەڵدەگرێت، کە بڕێکی TCP (سەوز) هەڵدەگرێت: سەردێڕی TCP و دراوەی ئەپ، بۆ نموونە بەشێک لە لاپەڕەتۆڕێک. خوارەوە: هەمان شت بە داتاگرامێکی UDP (پرتەقاڵی): سەردێڕی UDP و دراوەی ئەپ. دەق: پاکێتی IP بڕ یان داتاگرام هەڵدەگرێت و فرەیم پاکێتەکە هەڵدەگرێت. هەڵە: «TCP پاکێت دەنێرێت و UDP داتاگرام»؛ TCP بڕ دەنێرێت و IP پاکێت.
A segment or a datagram rides inside an IP packet. یان لە ناو دەڕوات.CêIT

Both TCP and UDP carry a checksumTCP و UDP هەردووکیان پشکنینی کۆ هەڵدەگرن

A checksum is a short number computed from the data. The sender puts it in the header; the receiver computes it again, and a different result means the segment was damaged on the way. TCP and UDP both use the Internet checksum, a one's-complement sum — one's complement is taught in Logic Design. Here it is with tiny 4-bit words: add the words; if a carry comes out of the top bit, wrap it around and add it at the bottom; then flip every bit. The receiver adds all the words and the checksum: all 1s means no error was found.

ژمارەیەکی کورتە کە لە دەژمێردرێت. نێرەر دەیخاتە ناو سەردێڕەکەوە؛ وەرگر دووپاتە دەیژمێرێتەوە و ئەنجامێکی جیاواز واتای ئەوەیە کە لە ڕێگادا تێکچووە. و هەردووکیان ئینتەرنێت بەکار دەهێنن، کە کۆکردنەوەیەکە بە — تەواوکەری یەک لە دیزاینی دەخوێندرێت. لێرەدا بە وشەی بچووکی 4 نیشان دراوە: وشەکان کۆ بکەرەوە؛ ئەگەر لە سەرووترین زیادی کرد، بیگەڕێنەوە و لە خوارەوە زیادی بکە؛ پاشان هەموو پێچەوانە بکەرەوە. وەرگر هەموو وشەکان و کۆ دەکاتەوە: ئەگەر هەمووی 1 بوو، هیچ هەڵەیەک نەدۆزراوەتەوە.

Sender: 1011 plus 0110 gives 1 0001, five bits with a carry. Step 1: wrap the carry around, 0001 + 1 = 0010. Step 2: flip every bit, 0010 becomes 1101: the checksum, sent in the header. Receiver: 1011 + 0110 + 1101 = 1111, all 1s, so no error was found and the data is kept. If one bit changed on the way (0110 became 0111), 1011 + 0111 + 1101 gives 0001, not all 1s, so the data is damaged and dropped. TCP, UDP and IPv4 do exactly this with 16-bit words (RFC 1071). A dropped TCP segment is sent again; a dropped UDP datagram is simply gone.نێرەر: 1011 کۆ 0110 دەکاتە 1 0001، پێنج بیت بە بیتێکی زیادەوە. هەنگاوی 1: بیتە زیادەکە بگەڕێنەوە، 0001 + 1 = 0010. هەنگاوی 2: هەموو بیتێک پێچەوانە بکەرەوە، 0010 دەبێتە 1101: پشکنینی کۆکە، کە لە سەردێڕەکەدا دەنێردرێت. وەرگر: 1011 + 0110 + 1101 = 1111، هەمووی 1ـە، کەواتە هیچ هەڵەیەک نەدۆزرایەوە و دراوەکە وەردەگیرێت. ئەگەر یەک بیت لە ڕێگادا بگۆڕێت (0110 بووە 0111)، 1011 + 0111 + 1101 دەکاتە 0001، کە هەمووی 1 نییە، کەواتە دراوەکە تێکچووە و فڕێ دەدرێت. TCP، UDP و IPv4 ڕێک ئەمە دەکەن بە وشەی 16 بیتی (RFC 1071). بڕێکی TCPـی فڕێدراو دووپاتە دەنێردرێتەوە؛ داتاگرامێکی UDPـی فڕێدراو بە تەواوی دەڕوات.
Add, wrap the carry, flip the bits; the receiver expects all 1s.کۆ بکەرەوە، زیادەکە بگەڕێنەوە، پێچەوانە بکەرەوە؛ وەرگر چاوەڕێی هەمووی 1 دەکات.CêIT
ChecksumNeso Academy · Englishئینگلیزی · 1.3M viewsبینین · 21K likesلایک

The checksum worked through with binary words: add them, wrap the carry around and flip the bits; the receiver adds everything and checks for all 1s.

بە نموونەی وشەی : وشەکان کۆ بکەرەوە، زیادەی سەرەوە بگەڕێنەوە بۆ خوارەوە و هەموو پێچەوانە بکەرەوە؛ وەرگر هەموویان کۆ دەکاتەوە و سەیر دەکات کە هەمووی 1 بێت.

Whole video: the sender's and the receiver's side of the one's-complement checksum, with a worked example.

هەموو ڤیدیۆکە: لای نێرەر و لای وەرگری بە ، لەگەڵ نموونەیەکی چارەسەرکراو.

Both TCP and UDP carry a checksumTCP و UDP هەردووکیان پشکنینی کۆ هەڵدەگرن

The real thing: 16-bit wordsشتە ڕاستەقینەکە: وشەی ⁦16⁩ بیتی

Real checksums use 16-bit words (RFC 1071). This Python program computes the checksum of the 8 bytes that RFC 1071 uses as its example, checks it the way a receiver does, and then changes one bit.

ڕاستەقینە وشەی ⁦16⁩ بەکار دەهێنن ⁦(RFC 1071)⁩. ئەم بەرنامە Pythonـە ئەو 8 دەژمێرێت کە ⁦RFC 1071⁩ وەک نموونە بەکاریان دەهێنێت، وەک وەرگرێک دەیپشکنێت و پاشان یەک دەگۆڕێت.

checksum16.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
def ones_complement_sum(data):
    total = 0
    for i in range(0, len(data), 2):
        word = (data[i] << 8) + data[i + 1]    # two bytes -> one 16-bit word
        total += word
        total = (total & 0xFFFF) + (total >> 16)   # wrap the carry around
    return total

data = bytes([0x00, 0x01, 0xF2, 0x03, 0xF4, 0xF5, 0xF6, 0xF7])
s = ones_complement_sum(data)
checksum = ~s & 0xFFFF                          # flip every bit
print(f"sum      = {s:04x}")
print(f"checksum = {checksum:04x}")

# The receiver adds the same words AND the checksum:
received = data + checksum.to_bytes(2, "big")
print(f"receiver = {ones_complement_sum(received):04x}")   # ffff = no error found

damaged = bytes([0x00, 0x01, 0xF2, 0x13]) + received[4:]   # one bit changed
print(f"damaged  = {ones_complement_sum(damaged):04x}")
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 6

Wrap-around: any carry above 16 bits is added back at the bottom.

گەڕاندنەوە: هەر لە سەرووی ⁦16⁩ زیاد بێت لە خوارەوە دەخرێتەوە سەری.

Lineدێڕی 11

~s & 0xFFFF flips all 16 bits: the one's complement.

~s & 0xFFFF هەموو ⁦16⁩ پێچەوانە دەکاتەوە: .

Lineدێڕی 17

The receiver's sum including the checksum is ffff (all 1s): no error found.

کۆی وەرگر لەگەڵ ffffـە (هەمووی ⁦1⁩): هیچ هەڵەیەک نەدۆزرایەوە.

The checksum covers the header, the data and a pseudo-header with the two IP addresses, so a segment delivered to the wrong host is caught too. A damaged segment or datagram is simply thrown away: TCP notices the missing bytes and resends them, UDP does nothing. In UDP over IPv4 an all-zero checksum means the sender did not compute one (over IPv6 the UDP checksum is required); TCP's checksum is never optional. It catches accidents, not attackers — protection against deliberate changes comes from TLS.

سەردێڕ، و سەردێڕێکی ساختە دەگرێتەوە کە دوو تێدایە، بۆیە کە بۆ هەڵە بگات ئەویش دەدۆزرێتەوە. یان تێکچوو تەنیا فڕێ دەدرێت: ونبوو دەبینێت و دووپاتەیان دەنێرێتەوە، هیچ ناکات. لە بە سەر ، سفر واتای ئەوەیە کە نێرەر هیچی نەژماردووە (بە سەر ناچارییە)؛ هەرگیز ئارەزوومەندانە نییە. ڕووداوی ڕێکەوت دەگرێت، نەک — پاراستن لە گۆڕینی ئەنقەست لە TLSـەوە دێت.

QUIC and HTTP/3: reliable, but over UDPQUIC و ⁦HTTP/3⁩: متمانەپێکراو، بەڵام بە سەر UDPـدا

Today a large part of web traffic does not use TCP at all. HTTP/3 (RFC 9114, 2022) runs over QUIC (RFC 9000, 2021), and QUIC runs over UDP, normally on UDP port 443. QUIC does TCP's jobs itself: it sets up a connection, numbers its packets, acknowledges them, resends what was lost and controls the flow and the congestion. It also always encrypts with TLS 1.3. Why build it on UDP instead of making a new protocol next to TCP? Many firewalls and home routers on the Internet pass only TCP and UDP, and QUIC lives inside the application, so a browser update can improve it.

ئەمڕۆ بەشێکی گەورەی هاتوچۆی وێب هەر بەکار ناهێنێت. ⁦HTTP/3⁩ (⁦RFC 9114⁩، ⁦2022⁩) بە سەر (⁦RFC 9000⁩، ⁦2021⁩)دا کار دەکات و بە سەر ، ئاسایی لەسەر ⁦443⁩ی . کارەکانی خۆی دەکات: پەیوەندی دادەمەزرێنێت، ژمارە دەکات، دانیان پێدا دەنێت، ونبووەکان دووپاتە دەنێرێتەوە و ڕەوت و قەرەباڵغی کۆنترۆڵ دەکات. هەروەها هەمیشە بە ⁦TLS 1.3⁩ دەکات. بۆچی لە سەر دروست کرا، نەک نوێ لە تەنیشت ؟ زۆرێک لە و ماڵەوە لە تەنیا و تێدەپەڕێنن و لە ناو دەژی، بۆیە نوێکردنەوەیەکی دەتوانێت باشتری بکات.

Two protocol stacks side by side. Left, HTTP/1.1 and HTTP/2: HTTP on top of TLS encryption, on top of TCP, on top of IP. Right, HTTP/3: HTTP/3 on top of QUIC, on top of UDP, on top of IP. A list says QUIC does the jobs of TCP itself: connection set-up, numbering and ACKs, resending lost data, flow and congestion control, plus encryption that is always on, with TLS 1.3 inside. Bottom: over TCP one lost packet makes every file of the page wait, because all files share one byte stream; over QUIC each file has its own stream, so only the stream that lost data waits. QUIC is RFC 9000 (2021); HTTP/3 is RFC 9114 (2022).دوو ستوونی پرۆتۆکۆڵ لە تەنیشت یەک. چەپ، HTTP/1.1 و HTTP/2: HTTP لە سەر شفرەکردنی TLS، لە سەر TCP، لە سەر IP. ڕاست، HTTP/3: HTTP/3 لە سەر QUIC، لە سەر UDP، لە سەر IP. لیستێک دەڵێت QUIC کارەکانی TCP خۆی دەکات: دامەزراندنی پەیوەندی، ژمارەکردن و ACK، ناردنەوەی دراوەی ونبوو، کۆنترۆڵی ڕەوت و کۆنترۆڵی قەرەباڵغی، لەگەڵ شفرەکردنی هەمیشە چالاک بە TLS 1.3. خوارەوە: لە TCPـدا یەک پاکێتی ونبوو هەموو فایلەکانی لاپەڕەکە ڕادەگرێت، چونکە هەموویان یەک زنجیرە بایت بەکار دەهێنن؛ لە QUICـدا هەر فایلێک زنجیرەی خۆی هەیە، بۆیە تەنیا ئەو زنجیرەیەی دراوەی لێ ون بووە چاوەڕێ دەکات. QUIC RFC 9000ـە (2021)؛ HTTP/3 RFC 9114ـە (2022).
HTTP/3 moved the web from TCP to QUIC over UDP.⁦HTTP/3⁩ وێبی لە گواستەوە بۆ بە سەر .CêIT

So “UDP is unreliable” describes UDP itself, not what is built on it: QUIC gives the web a fully reliable, encrypted transport on top of UDP. When a network blocks UDP port 443, the browser simply falls back to HTTP/2 over TCP. HTTP itself is in HTTP and the request cycle, its three versions are compared in HTTP/1.1, HTTP/2 and HTTP/3, and where TLS sits is in OSI layers 6 and 7.

کەواتە « نامتمانەپێکراوە» باسی خودی دەکات، نەک ئەوەی لە سەری دروست دەکرێت: گواستنەوەیەکی تەواو متمانەپێکراو و پارێزراو بە لە سەر دەداتە وێب. کاتێک ڕێگە لە ⁦443⁩ی دەگرێت، بە ئاسانی دەگەڕێتەوە بۆ ⁦HTTP/2⁩ بە سەر . خودی لە HTTP و خولی داواکاری باس کراوە، سێ وەشانەکەی لە ⁦HTTP/1.1⁩، ⁦HTTP/2⁩ و ⁦HTTP/3⁩ بەراورد کراون و شوێنی لە چینەکانی 6 و 7ی OSI.

DNS uses bothDNS هەردووکیان بەکار دەهێنێت

Microsoft's documentation, like the DNS standards, says that DNS works over both TCP and UDP, on port 53. A normal question (“what is the address of www.example.com?”) and its answer each fit in one small UDP datagram: no handshake, so the answer comes quickly. If the answer is too big for the UDP message, the server sends a shortened answer with the TC (truncated) flag set, and the client asks the same question again over TCP. Copying a whole zone from one DNS server to another (a zone transfer) always uses TCP. Since RFC 7766 (2016) every general-purpose DNS program must support both.

بەڵگەنامەکانی Microsoft، وەک ستانداردەکانی ، دەڵێن بە سەر هەردوو و کار دەکات، لەسەر ⁦53⁩. پرسیارێکی ئاسایی («ناونیشانی ⁦www.example.com⁩ چییە؟») و وەڵامەکەی هەریەکەیان لە یەک بچووکی جێیان دەبێتەوە: بێ ، بۆیە وەڵامەکە خێرا دێت. ئەگەر وەڵامەکە بۆ نامەی زۆر گەورە بێت، وەڵامێکی کورتکراوە دەنێرێت و ئاڵای TC ⁦(truncated)⁩ دادەنێت و هەمان پرسیار دووپاتە بە دەکاتەوە. کۆپیکردنی هەموو ناوچەیەک لە بۆ یەکێکی تر (zone transfer) هەمیشە بەکار دەهێنێت. لە ⁦RFC 7766⁩ـەوە ⁦(2016)⁩ هەموو بەرنامەیەکی گشتیی دەبێت پشتگیریی هەردووکیان بکات.

Three small scenes between a client and a DNS server, all on port 53. 1: a normal question, www.example.com?, goes over UDP 53 and the answer 192.0.2.80 comes back in one small UDP datagram. 2: the UDP answer is cut short with TC = 1 (truncated), so the client asks the same question over TCP 53 and gets the full answer in TCP segments. 3: copying a whole zone between two DNS servers (AXFR) uses TCP 53. Notes: since 2016 (RFC 7766) every DNS program must support both; with EDNS, UDP answers of up to about 1,232 bytes fit; the old 512-byte limit was a DNS rule, not a UDP limit.سێ دیمەنی بچووک لە نێوان ڕاژەخوازێک و ڕاژەکارێکی DNS، هەموویان لەسەر پۆرتی 53. 1: پرسیارێکی ئاسایی، www.example.com؟، بە UDP 53 دەڕوات و وەڵامی 192.0.2.80 لە یەک داتاگرامی بچووکی UDPـدا دەگەڕێتەوە. 2: وەڵامی UDP بە TC = 1 (کورتکراوە) دەبڕدرێت، بۆیە ڕاژەخوازەکە هەمان پرسیار بە TCP 53 دەکاتەوە و وەڵامی تەواو لە بڕەکانی TCPـدا وەردەگرێت. 3: کۆپیکردنی هەموو ناوچەیەک لە نێوان دوو ڕاژەکاری DNS (AXFR) TCP 53 بەکار دەهێنێت. تێبینی: لە 2016ـەوە (RFC 7766) هەموو بەرنامەیەکی DNS دەبێت پشتگیریی هەردووکیان بکات؛ بە EDNS، وەڵامی UDP تا نزیکەی 1,232 بایت جێی دەبێتەوە؛ سنووری کۆنی 512 بایت یاسایەکی DNS بوو، نەک سنوورێکی UDP.
Small answers over UDP; big answers and zone transfers over TCP.وەڵامی بچووک بە ؛ وەڵامی گەورە و zone transfer بە .CêIT

VPN tunnels ride on UDPتونێلەکانی VPN بە سەر UDPـدا دەڕۆن

A VPN builds an encrypted tunnel across the Internet. Your laptop puts each of its packets — often the TCP segments of a web page — inside the VPN's own encrypted packets, and most VPNs send those as UDP datagrams. WireGuard uses only UDP; OpenVPN uses UDP port 1194 unless you choose TCP; and IPsec VPNs that pass through a home router use UDP port 4500. What a VPN is for is explained in VPNs.

تونێلێکی شفرەکراو بە ناو دروست دەکات. هەر خۆی — زۆر جار — دەخاتە ناو شفرەکراوەکانی خودی و زۆربەی ئەو وەک دەنێرن. WireGuard تەنیا بەکار دەهێنێت؛ OpenVPN ⁦1194⁩ی بەکار دەهێنێت مەگەر خۆت هەڵبژێریت؛ IPsecـیش، کاتێک بە ماڵەوەدا تێدەپەڕێت، ⁦4500⁩ی بەکار دەهێنێت. بۆ چییە لە VPNـەکاندا ڕوون کراوەتەوە.

Aram's laptop, the VPN client, on the left; a VPN server and then a web server on the right. Between the laptop and the VPN server runs an encrypted tunnel across the Internet that carries UDP datagrams. Each datagram holds a TCP segment: segments 1, 2 and 3. Datagram 2 is crossed out: lost. From the VPN server to the web server the traffic is plain TCP. Three steps below: 1, each TCP segment goes inside an encrypted UDP datagram; 2, datagram 2 is lost and nothing in the tunnel resends it; 3, the TCP inside sees the gap and sends segment 2 again, end to end. Bottom: a tunnel over TCP would resend one loss twice, by the outer and the inner TCP, and the whole tunnel would wait. WireGuard uses UDP only; OpenVPN uses UDP 1194 by default; IPsec through a home router uses UDP 4500.لاپتۆپی ئارام، ڕاژەخوازی VPN، لە لای چەپ؛ ڕاژەکارێکی VPN و پاشان ڕاژەکارێکی وێب لە لای ڕاست. لە نێوان لاپتۆپەکە و ڕاژەکاری VPNـەکەدا تونێلێکی شفرەکراو بە ناو ئینتەرنێتدا هەیە کە داتاگرامەکانی UDP هەڵدەگرێت. هەر داتاگرامێک بڕێکی TCP لە خۆ دەگرێت: بڕەکانی 1، 2 و 3. داتاگرامی 2 خاچی لەسەرە: ون بووە. لە ڕاژەکاری VPNـەوە بۆ ڕاژەکاری وێبەکە هاتوچۆکە TCPـی ئاساییە. لە خوارەوە سێ هەنگاو: 1، هەر بڕێکی TCP دەچێتە ناو داتاگرامێکی شفرەکراوی UDPـەوە؛ 2، داتاگرامی 2 ون دەبێت و هیچ شتێکی ناو تونێلەکە دووپاتەی نانێرێتەوە؛ 3، TCPـی ناوەوە کەلێنەکە دەبینێت و بڕی 2 لە سەرێکەوە بۆ سەرەکەی تر دووپاتە دەنێرێتەوە. لە خوارەوە: تونێلێک بە سەر TCPـدا یەک ونبوون دوو جار دەنێرێتەوە، لەلایەن TCPـی دەرەوە و ناوەوە و هەموو تونێلەکە چاوەڕێ دەکات. WireGuard تەنیا UDP؛ OpenVPN بە شێوەی بنەڕەت UDP 1194؛ IPsec لە پشت ڕێدۆزی ماڵەوە UDP 4500.
The tunnel may lose a datagram; the TCP connection inside gets the data back.تونێلەکە لەوانەیە ون بکات؛ پەیوەندیی ناوەوە دەگەڕێنێتەوە.CêIT

Why UDP? Because losing a piece of the tunnel does no harm: the protocol inside takes care of it. If a datagram is lost, nothing in the tunnel resends it; the TCP connection inside sees the gap and resends the missing segment itself, end to end. A tunnel over TCP would resend the same loss twice — the outer TCP and the inner TCP, each with its own timers — and everything in the tunnel would wait. For this reason WireGuard does not offer TCP at all.

بۆچی ؟ چونکە ونبوونی پارچەیەکی تونێلەکە زیانی نییە: ناوەوە چارەسەری دەکات. ئەگەر ون بێت، هیچ شتێکی ناو تونێلەکە دووپاتە ناینێرێتەوە؛ پەیوەندیی ناوەوە کەلێنەکە دەبینێت و خۆی ونبووەکە لە سەرێکەوە بۆ سەرەکەی تر دووپاتە دەنێرێتەوە. تونێلێک بە سەر هەمان ونبوون دوو جار دەنێرێتەوە — دەرەوە و ناوەوە، هەریەکەیان بە خۆی — و هەموو شتێکی ناو تونێلەکە چاوەڕێ دەکات. بۆیە WireGuard هەر پێشکەش ناکات.

Finding each other on a LAN: only UDP can ask everyoneدۆزینەوەی یەکتر لە ڕایەڵەی ناوچەییدا: تەنیا UDP دەتوانێت لە هەمووان بپرسێت

How does your phone find the smart TV, the printer or a friend's game on the same Wi-Fi before it knows their addresses? It sends one small question to every device on the LAN — a broadcast, or a multicast to a group address (unicast, broadcast and multicast) — and only the devices that match answer. This needs UDP: a TCP connection always joins exactly two programs, so TCP cannot send one segment to many receivers.

مۆبایلەکەت چۆن ، یان یارییەکی هاوڕێکەت لەسەر هەمان دەدۆزێتەوە، پێش ئەوەی ناونیشانەکانیان بزانێت؟ یەک پرسیاری بچووک بۆ هەموو ئامێرێکی ناو دەنێرێت — ، یان بۆ ناونیشانێکی گرووپ (تاکپەخش، پەخشکردن و فرەپەخش) — و تەنیا ئەو ئامێرانە وەڵام دەدەنەوە کە لەگەڵ پرسیارەکە دەگونجێن. ئەمە پێویستی بە : پەیوەندییەکی هەمیشە ڕێک دوو بەرنامە بە یەکەوە دەبەستێتەوە، بۆیە ناتوانێت یەک بۆ چەند وەرگرێک بنێرێت.

Animation in three steps on a home Wi-Fi LAN, 192.168.1.0/24, with Hana's phone (192.168.1.25), a smart TV (192.168.1.40), a printer, a laptop and a game console. Step 1: the phone sends one UDP datagram to everyone, a multicast to 224.0.0.251 on port 5353 (mDNS), asking “Is there a TV here?”; every device receives it. Step 2: every device hears the question, but only the TV answers: living-room-tv.local = 192.168.1.40. Step 3: the phone now knows the address and opens an ordinary TCP connection to the TV, two programs. A side panel says: a TCP connection always joins exactly two programs; one message to many devices needs UDP, broadcast or multicast. Discovery on UDP: DHCP Discover, broadcast, port 67; mDNS names, multicast, port 5353; SSDP (UPnP), multicast, port 1900; LAN games, “a game is open here”. After discovery, the real talk usually moves to TCP.
Animation in three steps on a home Wi-Fi LAN, 192.168.1.0/24, with Hana's phone (192.168.1.25), a smart TV (192.168.1.40), a printer, a laptop and a game console. Step 1: the phone sends one UDP datagram to everyone, a multicast to 224.0.0.251 on port 5353 (mDNS), asking “Is there a TV here?”; every device receives it. Step 2: every device hears the question, but only the TV answers: living-room-tv.local = 192.168.1.40. Step 3: the phone now knows the address and opens an ordinary TCP connection to the TV, two programs. A side panel says: a TCP connection always joins exactly two programs; one message to many devices needs UDP, broadcast or multicast. Discovery on UDP: DHCP Discover, broadcast, port 67; mDNS names, multicast, port 5353; SSDP (UPnP), multicast, port 1900; LAN games, “a game is open here”. After discovery, the real talk usually moves to TCP.
One UDP question to everyone, one answer, then a TCP connection between two devices.یەک پرسیاری بۆ هەمووان، یەک وەڵام، پاشان پەیوەندییەکی لە نێوان دوو ئامێردا.CêIT

You use such discovery every day. A new laptop's first DHCP message is a broadcast to UDP port 67 (DORA). Printers, smart TVs and phones find each other's names with mDNS on UDP port 5353 (peer names). UPnP devices announce themselves with SSDP on UDP port 1900, and LAN games broadcast “a game is open here”. After the discovery, the real conversation usually moves to an ordinary TCP connection between the two devices.

ڕۆژانە ئەم جۆرە دۆزینەوەیە بەکار دەهێنیت. یەکەم پەیامی نوێ بۆ ⁦67⁩ی (DORA). ، و مۆبایلەکان بە mDNS لەسەر ⁦5353⁩ی ناوی یەکتر دەدۆزنەوە (ناوی تاکەکان). ئامێرەکانی UPnP بە SSDP لەسەر ⁦1900⁩ی خۆیان ڕادەگەیەنن و یارییەکانی بە ڕادەگەیەنن کە «لێرە یارییەک کراوەیە». دوای دۆزینەوەکە، گفتوگۆ ڕاستەقینەکە زۆربەی جار دەچێتە سەر پەیوەندییەکی ئاسایی لە نێوان دوو ئامێرەکەدا.

Which protocol for which application?کام پرۆتۆکۆڵ بۆ کام ئەپ؟

TCP and UDP side by side. و لە تەنیشت یەک.
FeatureتایبەتمەندیTCPUDP
DeliveryگەیاندنReliable: every byte or an errorمتمانەپێکراو: هەموو یان هەڵەBest effort: no guaranteeباشترین هەوڵ: بێ گەرەنتی
Connection set-upدامەزراندنی پەیوەندیYes, three-way handshakeبەڵێ، Noنەخێر
Error detection (checksum)دۆزینەوەی هەڵە ()YesبەڵێYesبەڵێ
Resending lost data ونبووYesبەڵێNoنەخێر
Ordered deliveryگەیاندن بە ڕیزYesبەڵێNoنەخێر
Flow controlYes (window)بەڵێ ()Noنەخێر
Congestion controlYesبەڵێNoنەخێر
Headerسەردێڕ20–60 bytes⁦20–60⁩ 8 bytes8
Unit of dataیەکەی SegmentDatagram
Typical usesبەکارهێنانی باوWeb (HTTP/1.1, HTTP/2), e-mail (SMTP, IMAP, POP3), FTP, SSH, chat text, MQTTوێب (⁦HTTP/1.1⁩، ⁦HTTP/2⁩)، (، ، )، ، ، نووسینی چات، DNS questions, DHCP, voice and video calls (RTP), game moves, TFTP, SNMP, RIP, VPN tunnels (WireGuard), LAN discovery (mDNS, SSDP), QUIC/HTTP/3پرسیاری ، ، پەیوەندیی دەنگی و ڤیدیۆیی ⁦(RTP)⁩، جووڵەی یاری، ، SNMP، ، تونێلی ⁦(WireGuard)⁩، دۆزینەوە لە (mDNS، SSDP)، و ⁦HTTP/3⁩

Some everyday examples. SMTP, which carries e-mail between servers, runs over TCP (port 25): a letter with missing words is no use. A speed-test website, like every site that uses HTTP, runs over TCP and opens several connections at once to fill the line. A YouTube video you watch — even a live one — comes over HTTP, today often HTTP/3 over QUIC, so no part of it is lost. Real-time calls are different: a WhatsApp, Messenger or Teams call sends its voice and video in UDP datagrams, and a lost piece is simply skipped. A game often uses both: UDP for the players' moves, TCP for logging in, chat and voice messages. In the Internet of Things, MQTT runs over TCP (see IoT data protocols).

چەند نموونەیەکی ڕۆژانە. ، کە لە نێوان دەگوازێتەوە، بە سەر دا کار دەکات ( ⁦25⁩): نامەیەک کە وشەی تێدا کەم بێت بێسوودە. ماڵپەڕێکی پشکنینی خێرایی، وەک هەموو ماڵپەڕێک کە بەکار دەهێنێت، بە سەر کار دەکات و لە یەک کاتدا چەند پەیوەندییەک دەکاتەوە تا هێڵەکە پڕ بکات. ڤیدیۆیەکی YouTube کە سەیری دەکەیت — تەنانەت ڕاستەوخۆش — بە دێت، ئەمڕۆ زۆر جار ⁦HTTP/3⁩ بە سەر ، بۆیە هیچ بەشێکی ون نابێت. پەیوەندیی ڕاستەوخۆ جیاوازە: پەیوەندییەکی WhatsApp، Messenger یان Teams دەنگ و ڤیدیۆکەی لە دەنێرێت و پارچەی ونبوو تەنیا تێدەپەڕێنرێت. یارییەک زۆر جار هەردووکیان بەکار دەهێنێت: بۆ جووڵەی یاریزانەکان، بۆ چوونەژوورەوە، چات و نامەی دەنگی. لە ، بە سەر کار دەکات (بڕوانە پرۆتۆکۆڵەکانی دراوەی IoT).

A chart titled “Which transport does each application use? (2026)”. A green TCP column: web pages over HTTP/1.1 and HTTP/2, e-mail with SMTP, IMAP and POP3, files with FTP and SFTP, remote login with SSH, chat text and app updates. An orange UDP column: DNS questions (usually), DHCP for getting an address, voice and video calls (RTP), moves in online games, and TFTP, SNMP, RIP and NTP. A blue box, QUIC over UDP: HTTP/3 web pages and video, reliable like TCP, encrypted with TLS 1.3, UDP port 443, falls back to TCP if blocked. Bottom: DNS uses UDP for normal questions and TCP for big answers and zone transfers; a game often uses UDP for the moves and TCP for chat and log-in.خشتەیەک بە ناونیشانی «هەر ئەپێک کام گواستنەوە بەکار دەهێنێت؟ (2026)». ستوونێکی سەوزی TCP: لاپەڕەتۆڕەکان بە HTTP/1.1 و HTTP/2، ئیمەیڵ بە SMTP، IMAP و POP3، فایلەکان بە FTP و SFTP، چوونەژوورەوە لە دوورەوە بە SSH، نووسینی چات و نوێکردنەوەی ئەپەکان. ستوونێکی پرتەقاڵیی UDP: پرسیاری DNS (زۆربەی کات)، DHCP بۆ وەرگرتنی ناونیشان، پەیوەندیی دەنگی و ڤیدیۆیی (RTP)، جووڵە لە یاریی ئۆنلایندا، هەروەها TFTP، SNMP، RIP و NTP. چوارگۆشەیەکی شین، QUIC بە سەر UDPـدا: لاپەڕەتۆڕەکان و ڤیدیۆی HTTP/3، متمانەپێکراو وەک TCP، پارێزراو بە شفرەکردنی TLS 1.3، پۆرتی 443ی UDP، ئەگەر ڕێگەی لێ بگیرێت دەگەڕێتەوە بۆ TCP. خوارەوە: DNS بۆ پرسیاری ئاسایی UDP و بۆ وەڵامی گەورە و zone transfer TCP بەکار دەهێنێت؛ یارییەک زۆر جار UDP بۆ جووڵەکان و TCP بۆ چات و چوونەژوورەوە بەکار دەهێنێت.
Each application picks the transport that fits it.هەر ئەو گواستنەوەیە هەڵدەبژێرێت کە لەگەڵیدا دەگونجێت.CêIT

A shorter list of protocols and layers is in data communication; the port number of each service is in port numbers and sockets.

لیستێکی کورتتری و چینەکان لە پەیوەندیی دراوەدایە؛ ژمارەی هەر خزمەتگوزارییەک لە وانەی ژمارەی پۆرت و سۆکێتەکان هەیە.

Common mistakesهەڵە باوەکان

Exercisesڕاهێنانەکان

ExerciseڕاهێنانFill in the gapsبۆشاییەکان پڕ بکەرەوە

Two main protocols that are examples of TCP/IP transport-layer protocols are ___ and ___.

دوو سەرەکی کە نموونەی ⁦___⁩ و ⁦___⁩ن.

Show answerوەڵامەکە پیشان بدە

TCP and UDP.

و .

ExerciseڕاهێنانTCP or UDP?TCP یان UDP؟

For each application, say which transport protocol fits it and why: (a) uploading an assignment to the university's website; (b) a live voice call from Sulaimani to Erbil; (c) looking up the address of www.example.com; (d) managing a router from your laptop with SSH; (e) the players' moves in an online football game.

بۆ هەر بڵێ کام گواستنەوە لەگەڵیدا دەگونجێت و بۆچی: ⁦(a)⁩ ئەرکێک بۆ ماڵپەڕی زانکۆ؛ ⁦(b)⁩ پەیوەندییەکی دەنگیی ڕاستەوخۆ لە سلێمانییەوە بۆ هەولێر؛ ⁦(c)⁩ دۆزینەوەی ناونیشانی ⁦www.example.com⁩؛ ⁦(d)⁩ بەڕێوەبردنی لە بە ؛ ⁦(e)⁩ جووڵەی یاریزانەکان لە یارییەکی تۆپی پێی ئۆنلایندا.

Show answerوەڵامەکە پیشان بدە
  • (a) TCP: every byte of the file must arrive (HTTP over TCP, or HTTP/3 over QUIC, which is also reliable).
  • (b) UDP: a late piece of voice is useless; a short gap is better than waiting.
  • (c) UDP: one small question and one small answer on port 53; TCP only if the answer is truncated.
  • (d) TCP: every command and every character must arrive, in order (SSH uses TCP port 22).
  • (e) UDP: the newest position matters; an old one that arrives late is already out of date.
  • ⁦(a)⁩ : هەموو دەبێت بگات ( بە سەر ، یان ⁦HTTP/3⁩ بە سەر کە ئەویش متمانەپێکراوە).
  • ⁦(b)⁩ : پارچە دەنگێکی دواکەوتوو بێسوودە؛ بۆشاییەکی کورت باشترە لە چاوەڕوانی.
  • ⁦(c)⁩ : پرسیارێکی بچووک و وەڵامێکی بچووک لەسەر ⁦53⁩؛ تەنیا ئەگەر وەڵامەکە کورتکرابێتەوە.
  • ⁦(d)⁩ : هەموو فەرمانێک و هەموو پیتێک دەبێت بە ڕیز بگات ( ⁦22⁩ی بەکار دەهێنێت).
  • ⁦(e)⁩ : نوێترین شوێن گرنگە؛ شوێنێکی کۆن کە درەنگ بگات پێشتر کۆن بووە.
ExerciseڕاهێنانCompute a 4-bit checksumپشکنینێکی کۆی 4 بیتی بژمێرە

A sender has the two 4-bit words 1100 and 1010. Compute the checksum the way TCP and UDP do, then check it as the receiver.

نێرەرێک دوو وشەی 4 هەیە: ⁦1100⁩ و ⁦1010⁩. وەک و بژمێرە، پاشان وەک وەرگر بیپشکنە.

Hintئاماژە

Add, wrap any fifth bit back to the bottom, then flip every bit.

کۆ بکەرەوە، پێنجەم بگەڕێنەوە بۆ خوارەوە، پاشان هەموو پێچەوانە بکەرەوە.

Show answerوەڵامەکە پیشان بدە
1100+1010=1 01100110+1=0111(wrap the carry)0111‾=1000(checksum)1100+1010+1000=1 1110  →  1110+1=1111\begin{aligned} 1100 + 1010 &= 1\,0110 \\ 0110 + 1 &= 0111 \quad\text{(wrap the carry)} \\ \overline{0111} &= 1000 \quad\text{(checksum)} \\ 1100 + 1010 + 1000 &= 1\,1110 \;\to\; 1110 + 1 = 1111 \end{aligned}

The checksum is 1000. The receiver's sum is 1111 — all 1s, so no error was found.

⁦1000⁩ـە. کۆی وەرگر ⁦1111⁩ـە — هەمووی 1، کەواتە هیچ هەڵەیەک نەدۆزرایەوە.

ExerciseڕاهێنانHow many segments?چەند بڕ؟

A file of 2,920,000 bytes is sent over Ethernet with an MSS of 1,460 bytes. How many TCP segments carry it? Does the answer change on a faster line?

بە ⁦2,920,000⁩ بە سەر Ethernetـدا بە MSSی ⁦1,460⁩ دەنێردرێت. چەند هەڵیدەگرن؟ ئایا وەڵامەکە لەسەر هێڵێکی خێراتر دەگۆڕێت؟

Show answerوەڵامەکە پیشان بدە

2,920,000 ÷ 1,460 = 2,000 segments. No: a faster line sends the same 2,000 segments in less time.

⁦2,920,000 ÷ 1,460⁩ = ⁦2,000⁩ . نەخێر: هێڵێکی خێراتر هەمان ⁦2,000⁩ لە کاتێکی کەمتردا دەنێرێت.

Summaryپوختە

  • TCP and UDP are TCP/IP's two transport protocols. Both use ports, cut data into pieces and carry a checksum.
  • TCP (RFC 9293) is connection-oriented, reliable, ordered and full duplex, with flow and congestion control; header 20–60 bytes; its unit is the segment.
  • UDP (RFC 768) is connectionless and light: no handshake, no resending, no order; header 8 bytes; its unit is the datagram.
  • The checksum is a one's-complement sum: the receiver expects all 1s. It detects damage; only TCP recovers by resending.
  • Downloads, web pages, e-mail (SMTP!) and SSH use TCP; calls, game moves, DNS questions and DHCP use UDP; HTTP/3 uses QUIC over UDP; DNS uses both.
  • UDP also carries most VPN tunnels — the TCP inside resends what is lost — and discovery on a LAN, because only UDP can send to everyone (broadcast and multicast).
  • و دوو گواستنەوەی . هەردووکیان بەکار دەهێنن، دەکەنە پارچە و هەڵدەگرن.
  • ⁦(RFC 9293)⁩ ، متمانەپێکراو، بە ڕیز و ، بە و ؛ سەردێڕ ⁦20–60⁩ ؛ یەکەکەی .
  • ⁦(RFC 768)⁩ و سووکە: بێ ، بێ ، بێ ڕیز؛ سەردێڕ 8 ؛ یەکەکەی .
  • کۆکردنەوەیەکی : وەرگر چاوەڕێی هەمووی 1 دەکات. تێکچوون دەدۆزێتەوە؛ تەنیا بە چاکی دەکاتەوە.
  • ، ، (!) و بەکار دەهێنن؛ پەیوەندی، جووڵەی یاری، پرسیاری و ؛ ⁦HTTP/3⁩ بە سەر ؛ هەردووکیان.
  • زۆربەی تونێلەکانی هەڵدەگرێت — ناوەوە ونبوو دووپاتە دەنێرێتەوە — هەروەها دۆزینەوە لە ، چونکە تەنیا دەتوانێت بۆ هەمووان بنێرێت ( و ).

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Port Numbers and Socketsژمارەی پۆرت و سۆکێتەکان

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.

Appearanceڕووکار

Modeدۆخ
Styleشێواز
Coloursڕەنگەکان

Saved on this device only.تەنیا لەسەر ئەم ئامێرە پاشەکەوت دەکرێت.