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

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

How one IP address serves many programs: port numbers, physical vs logical ports, the three IANA ranges, the well-known ports, sockets and socket pairs, demultiplexing and reading netstat on Windows 11.

چۆن یەک خزمەت بە چەندین بەرنامە دەکات: ژمارەی ، و ، سێ بەشەکەی ، ، و جووتە ، دیمەڵتیپلێکسکردن و خوێندنەوەی netstat لەسەر ⁦Windows 11⁩.

13 min read14 خولەک خوێندنەوە · 15 stepsهەنگاو

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

  • Explain why port numbers are needed and tell physical ports from port numbers.
  • Name the three IANA port ranges and the well-known ports of common services.
  • Write sockets and socket pairs and explain demultiplexing.
  • Read the local address, foreign address, state and PID in netstat -ano.
  • ڕوونی بکەیتەوە بۆچی ژمارەی پێویستە و لە ژمارەی جیا بکەیتەوە.
  • سێ بەشەکەی و خزمەتگوزارییە باوەکان ناو ببەیت.
  • و جووتە بنووسیت و دیمەڵتیپلێکسکردن ڕوون بکەیتەوە.
  • ناونیشانی ناوخۆ، ناونیشانی دەرەکی، دۆخ و PID لە ⁦netstat -ano⁩دا بخوێنیتەوە.

One IP address, many programsیەک ناونیشانی IP، چەندین بەرنامە

Your laptop has one IP address, yet a browser, a mail app and a game all use the network at the same moment. When a segment arrives, which program should get it? The IP address only brings it to the right host. To reach the right program, the transport layer gives every conversation a second address: a port number, a 16-bit number from 0 to 65,535 in the TCP or UDP header. With port numbers many programs can share one IP address.

یەک هەیە، کەچی ، ئیمەیڵ و یارییەک هەموویان لە هەمان ساتدا بەکار دەهێنن. کاتێک دەگات، دەبێت بدرێت بە کام بەرنامە؟ تەنیا دەیگەیەنێتە دروستەکە. بۆ گەیشتن بە بەرنامە دروستەکە، ناونیشانێکی دووەم بە هەر گفتوگۆیەک دەدات: ژمارەی ، ژمارەیەکی ⁦16⁩ لە 0 تا ⁦65,535⁩ لە سەردێڕی یان . بە ژمارەی چەندین بەرنامە دەتوانن یەک بەش بکەن.

A letter addressed to 192.0.2.10, port 443, travels to an apartment building labelled 192.0.2.10. The building has four flats with numbers: 80 for the web server (HTTP), 443 for the web server (HTTPS), 25 for mail (SMTP) and 53 for DNS; flat 443 is highlighted. A note says: IP address = the building, which host; port number = the flat, which program; ports are 16 bits, 0 to 65,535.نامەیەک بۆ 192.0.2.10، پۆرتی 443، بەرەو باڵەخانەیەک دەڕوات کە ناوی 192.0.2.10ـە. باڵەخانەکە چوار شوقەی ژمارەداری هەیە: 80 بۆ ڕاژەکاری وێب (HTTP)، 443 بۆ ڕاژەکاری وێب (HTTPS)، 25 بۆ ئیمەیڵ (SMTP) و 53 بۆ DNS؛ شوقەی 443 دیار کراوە. تێبینییەک دەڵێت: ناونیشانی IP = باڵەخانەکە، کام میوانگر؛ ژمارەی پۆرت = شوقەکە، کام بەرنامە؛ پۆرتەکان 16 بیتن، 0 تا 65,535.
The IP address finds the building; the port number finds the flat. باڵەخانەکە دەدۆزێتەوە؛ ژمارەی شوقەکە.CêIT
A building in Erbilباڵەخانەیەک لە هەولێر

A courier brings a parcel to a building in Erbil: the street address gets it to the building, and the flat number gets it to the right family. On a network the IP address is the street address of the host and the port number is the flat number of the program.

نامەبەرێک پاکێتێک دەباتە باڵەخانەیەک لە هەولێر: ناونیشانی شەقامەکە دەیگەیەنێتە باڵەخانەکە و ژمارەی شوقەکە دەیگەیەنێتە خێزانە دروستەکە. لە ناونیشانی شەقامی و ژمارەی ژمارەی شوقەی بەرنامەکەیە.

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

Flats keep their numbers for years. A client program gets a new port number for almost every conversation.

شوقەکان ساڵانێک ژمارەکەیان دەمێنێت. بەرنامەیەکی بۆ نزیکەی هەموو گفتوگۆیەک ژمارەیەکی نوێ وەردەگرێت.

The idea of multiplexing was introduced in OSI layers 4 and 5; this lesson shows the numbers that make it work.

بیرۆکەی لە چینەکانی 4 و 5ی OSI ناسێنرا؛ ئەم وانەیە ئەو ژمارانە پیشان دەدات کە کاری پێ دەکەن.

What is a Port Number ? #1T3SO Tutorials · Kurdish (Sorani)کوردی (سۆرانی) · 3K viewsبینین · 70 likesلایک

In Kurdish: one server offers web, email and DNS at the same time, and the port number tells the server which program a message is for.

بە کوردی: لە یەک کاتدا وێب، و پێشکەش دەکات؛ ژمارەی بە دەڵێت نامەکە بۆ کام .

Whole video, in Kurdish: one server, many programs, told apart by port numbers. The addresses in the drawing are only labels.

هەموو ڤیدیۆکە، بە کوردی: یەک و چەند ، کە بە ژمارەی لێک جیا دەکرێنەوە. ناونیشانەکانی ناو وێنەکە تەنیا ناون.

Physical ports and logical portsدەرچەکان و پۆرتەکان

The word “port” has two meanings. A physical port is a socket on a device that you can touch and plug a connector into: the RJ45 Ethernet port of a network card, a USB port, or the old serial (RS-232) port, which modern PCs rarely have — Cisco console cables today use USB or RJ45. A logical port is the port number: only software, a number in the transport header. In Kurdish CêIT keeps the two apart: «» for the physical one, «» for the number. Physical ports and connectors are taught in ports and connectors.

وشەی «port» دوو واتای هەیە. کونێکە لەسەر ئامێرێک کە دەتوانیت دەستی لێ بدەیت و گەیەنەرێکی تێدا دابنێیت: ⁦RJ45⁩ـی Ethernet لە ، USB، یان زنجیرەیی کۆن ⁦(RS-232)⁩ کە کۆمپیوتەرە نوێیەکان کەم جار هەیانە — Cisco ئەمڕۆ USB یان ⁦RJ45⁩ بەکار دەهێنن. ژمارەی : تەنیا نەرمەکاڵایە، ژمارەیەکە لە سەردێڕی گواستنەوەدا. لە کوردیدا CêIT هەردووکیان لێک جیا دەکاتەوە: «» بۆ فیزیکییەکە، «» بۆ ژمارەکە. و گەیەنەرەکان لە دەرچەکان و گەیەنەرەکان دەخوێندرێن.

Two panels. Left, physical port (connector): drawings of an RJ45 Ethernet socket and a USB socket; you can touch it and a cable plugs in; hardware, OSI layer 1. Right, logical port (port number): a TCP header with dst port = 443; a 16-bit number in the TCP or UDP header; only software, it names a program; transport layer, OSI layer 4. Bottom: one RJ45 port can carry thousands of port numbers at the same time.دوو بەش. چەپ، دەرچە (فیزیکی): وێنەی دەرچەی RJ45ـی Ethernet و دەرچەی USB؛ دەتوانیت دەستی لێ بدەیت و کێبڵێکی تێدا دادەنرێت؛ ڕەقەکاڵا، چینی 1ی OSI. ڕاست، پۆرت (ژمارەی پۆرت): سەردێڕێکی TCP بە dst port = 443؛ ژمارەیەکی 16 بیتی لە سەردێڕی TCP یان UDPـدا؛ تەنیا نەرمەکاڵا، بەرنامەیەک ناو دەبات؛ چینی گواستنەوە، چینی 4ی OSI. خوارەوە: یەک دەرچەی RJ45 دەتوانێت لە یەک کاتدا هەزاران ژمارەی پۆرت هەڵبگرێت.
Same English word, two different things.هەمان وشەی ئینگلیزی، دوو شتی جیاواز.CêIT

Source port and destination portپۆرتی سەرچاوە و پۆرتی مەبەست

Every TCP segment and UDP datagram carries two port numbers. The destination port names the program on the remote host that should receive it; the source port names the program on the local host that sent it. A server program waits on a fixed, well-known port — a web server on 443 for HTTPS. The client's operating system gives each new conversation a temporary ephemeral port, chosen from a range of high numbers. In the reply the two numbers simply swap places.

هەموو و دوو ژمارەی هەڵدەگرن. مەبەست ئەو بەرنامەیە ناو دەبات لەسەر دوورەکە کە دەبێت وەری بگرێت؛ سەرچاوە ئەو بەرنامەیە ناو دەبات لەسەر ناوخۆییەکە کە ناردوویەتی. بەرنامەیەکی لەسەر جێگیر و ناسراو چاوەڕێ دەکات — لەسەر ⁦443⁩ بۆ . بە هەر گفتوگۆیەکی نوێ دەدات، لە ژمارە بەرزەکانەوە. لە وەڵامدا دوو ژمارەکە تەنیا جێ دەگۆڕنەوە.

A client laptop, 192.0.2.10, and a web server, 203.0.113.25. The request goes to the server with source port 49731 and destination port 443. The reply comes back with source port 443 and destination port 49731. Notes: 49731 is a temporary port chosen by the client's operating system; 443 is the well-known HTTPS port where the server program listens.لاپتۆپێکی ڕاژەخواز (192.0.2.10) و ڕاژەکارێکی وێب (203.0.113.25). داواکارییەکە بە پۆرتی سەرچاوە 49731 و پۆرتی مەبەست 443 دەچێت بۆ ڕاژەکارەکە. وەڵامەکە بە پۆرتی سەرچاوە 443 و پۆرتی مەبەست 49731 دەگەڕێتەوە. تێبینی: 49731 پۆرتی کاتییەکە کە سیستەمی وەگەڕخەری ڕاژەخوازەکە هەڵیبژاردووە؛ 443 پۆرتی ناسراوی HTTPSـە کە بەرنامەی ڕاژەکارەکە لێی چاوەڕێ دەکات.
Request: 49731 → 443. Reply: 443 → 49731.داواکاری: لە ⁦49731⁩ـەوە بۆ ⁦443⁩. وەڵام: لە ⁦443⁩ـەوە بۆ ⁦49731⁩.CêIT

The three port rangesسێ بەشی ژمارەی پۆرت

Port numbers are 16 bits, so there are 65,536 of them: 0 to 65,535. IANA, the Internet Assigned Numbers Authority, keeps the official list and splits the numbers into three ranges (RFC 6335). System or well-known ports, 0–1023, belong to standard services: 22 SSH, 53 DNS, 67/68 DHCP, 80 HTTP, 443 HTTPS. User or registered ports, 1024–49151, are registered for vendors' and newer services: 1883 MQTT, 3389 Remote Desktop, 46999 MediaBox. Dynamic, private or ephemeral ports, 49152–65535, are never assigned to anyone: operating systems take client ports from here. Both TCP and UDP (and the rarer SCTP and DCCP) use the same numbering, but TCP port 53 and UDP port 53 are separate doors.

ژمارەی ⁦16⁩ ، بۆیە ⁦65,536⁩ دانە هەن: 0 تا ⁦65,535⁩. ⁦(Internet Assigned Numbers Authority)⁩ لیستە فەرمییەکە دەپارێزێت و ژمارەکان دەکاتە سێ بەش ⁦(RFC 6335)⁩. یان سیستەم، ⁦0–1023⁩، هی خزمەتگوزارییە ستانداردەکانن: ⁦22⁩ ، ⁦53⁩ ، ⁦67/68⁩ ، ⁦80⁩ ، ⁦443⁩ . یان بەکارهێنەر، ⁦1024–49151⁩، بۆ کۆمپانیاکان و خزمەتگوزارییە نوێترەکان تۆمار دەکرێن: ⁦1883⁩ ، ⁦3389 Remote Desktop⁩، ⁦46999 MediaBox⁩. ، دینامیکی یان تایبەت، ⁦49152–65535⁩، هەرگیز بە کەس نادرێن: لێرەوە وەردەگرن. و (و SCTP و DCCPـی دەگمەنتریش) هەمان ژمارەکردن بەکار دەهێنن، بەڵام ⁦53⁩ی و ⁦53⁩ی دوو دەرگای جیاوازن.

Three coloured blocks. 0–1023: system or well-known ports, assigned by IANA, for example 22 SSH, 53 DNS, 67/68 DHCP, 80 HTTP and 443 HTTPS. 1024–49151: user or registered ports, registered with IANA, for example 1883 MQTT, 3389 RDP and 46999 MediaBox. 49152–65535: dynamic, private or ephemeral ports, never assigned, client ports chosen by the operating system (Windows: 49152–65535). Below, a bar drawn to scale: the well-known range is a thin sliver, 1.6 % of the 65,536 numbers; the registered range is 73.4 % and the dynamic range 25 %.سێ بلۆکی ڕەنگاوڕەنگ. 0–1023: پۆرتە ناسراوەکان یان هی سیستەم، IANA دیاریان دەکات، بۆ نموونە 22 SSH، 53 DNS، 67/68 DHCP، 80 HTTP و 443 HTTPS. 1024–49151: پۆرتە تۆمارکراوەکان یان هی بەکارهێنەر، لە IANA تۆمار دەکرێن، بۆ نموونە 1883 MQTT، 3389 RDP و 46999 MediaBox. 49152–65535: پۆرتە کاتییەکان، دینامیکی یان تایبەت، هەرگیز دیاری ناکرێن، ئەو پۆرتانەی ڕاژەخواز کە سیستەمی وەگەڕخەر هەڵیان دەبژێرێت (Windows: 49152–65535). لە خوارەوە شریتێک بە پێوەری ڕاستەقینە: بەشی ناسراو هێڵێکی زۆر باریکە، 1.6٪ی 65,536 ژمارەکە؛ بەشی تۆمارکراو 73.4٪ و بەشی دینامیکی 25٪.
Well-known 0–1023, registered 1024–49151, dynamic 49152–65535.ناسراو ⁦0–1023⁩، تۆمارکراو ⁦1024–49151⁩، دینامیکی ⁦49152–65535⁩.CêIT

The three port rangesسێ بەشی ژمارەی پۆرت

Where client ports come fromپۆرتەکانی ڕاژەخواز لە کوێوە دێن

When a program opens a connection, the operating system picks a free port from its dynamic range and gives it to that conversation only. Windows, since Vista, uses 49152–65535, as IANA recommends; older Windows versions used 1025–5000. Linux uses 32768–60999 by default. You can see the Windows range in the Command Prompt:

کاتێک بەرنامەیەک پەیوەندییەک دەکاتەوە، بەتاڵ لە بەشە دینامیکییەکەی هەڵدەبژێرێت و تەنیا بەو گفتوگۆیەی دەدات. Windows لە Vistaـوە ⁦49152–65535⁩ بەکار دەهێنێت، وەک پێشنیاری دەکات؛ وەشانە کۆنەکانی ⁦Windows 1025–5000⁩یان بەکار دەهێنا. Linux بە شێوەی بنەڕەت ⁦32768–60999⁩ بەکار دەهێنێت. دەتوانیت ئەم بەشەی Windows لە Command Promptـدا ببینیت:

Windows 11: show the dynamic port range⁦Windows 11⁩: پیشاندانی بەشی پۆرت دینامیکییەکانBATType in a terminalلە تێرمیناڵدا بینووسە
netsh int ipv4 show dynamicport tcp

49152 + 16384 − 1 = 65535: the whole dynamic range. This is why netstat on Windows shows client ports such as 49731 or 50112.

⁦49152 + 16384 − 1 = 65535⁩: هەموو بەشە دینامیکییەکە. لەبەر ئەمەیە netstat لەسەر Windows وەک ⁦49731⁩ یان ⁦50112⁩ پیشان دەدات.

The three port rangesسێ بەشی ژمارەی پۆرت

Looking up a port in the IANA registryدۆزینەوەی پۆرتێک لە تۆماری IANAـدا

The official answer to “what is port N?” is the IANA Service Name and Transport Protocol Port Number Registry, which anyone can search online. It lists each number separately for TCP and UDP. For example, port 1027: TCP 1027 is Reserved, and UDP 1027 is 6a44 (“IPv6 Behind NAT44 CPEs”). Lists copied from old websites often give wrong names, so check the registry before you trust a port table.

وەڵامی فەرمیی « N چییە؟» تۆماری Service Name and Transport Protocol Port Number Registryـی ، کە هەموو کەسێک دەتوانێت بە ئۆنلاین تێیدا بگەڕێت. هەر ژمارەیەک بۆ و بە جیا دەنووسێت. بۆ نموونە ⁦1027⁩: ⁦1027⁩ی Reserved (پارێزراو)ـە و ⁦1027⁩ی ⁦6a44⁩ـە («⁦IPv6 Behind NAT44 CPEs⁩»). ئەو لیستانەی لە ماڵپەڕە کۆنەکانەوە کۆپی کراون زۆر جار ناوی هەڵە دەدەن، بۆیە پێش ئەوەی متمانە بە خشتەیەکی بکەیت، تۆمارەکە بپشکنە.

A table in the style of the IANA registry, checked in November 2026: 53 tcp and udp, domain, Domain Name Server; 443 tcp and udp, https, http protocol over TLS/SSL; 1027 tcp, Reserved; 1027 udp, 6a44, IPv6 Behind NAT44 CPEs; 3389 tcp and udp, ms-wbt-server, MS WBT Server (Remote Desktop); 49152–65535, not assigned (dynamic). The two 1027 rows are highlighted. Bottom: port 1027 is not “Exosee”: TCP 1027 is reserved and UDP 1027 is 6a44.خشتەیەک بە شێوەی تۆماری IANA، لە تشرینی دووەمی 2026دا پشکنراوە: 53 tcp و udp، domain، Domain Name Server؛ 443 tcp و udp، https، http protocol over TLS/SSL؛ 1027 tcp، Reserved؛ 1027 udp، 6a44، IPv6 Behind NAT44 CPEs؛ 3389 tcp و udp، ms-wbt-server، MS WBT Server (Remote Desktop)؛ 49152–65535، دیاری نەکراو (دینامیکی). دوو دێڕەکەی 1027 دیار کراون. خوارەوە: پۆرتی 1027 «Exosee» نییە: 1027ی TCP پارێزراوە و 1027ی UDP 6a44ـە.
Check the registry: the same number can mean different things for TCP and UDP.تۆمارەکە بپشکنە: هەمان ژمارە دەکرێت بۆ و واتای جیاوازی هەبێت.CêIT

Ports you will meet every dayئەو پۆرتانەی هەموو ڕۆژێک دەیانبینیت

Every common service has a fixed port, so a client knows where to knock. In this picture the application is on the left, its port in the middle and the transport protocol it uses on the right. Most services use one protocol; DNS uses both, and HTTPS adds UDP 443 for HTTP/3.

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

Thirteen applications, each joined to its port number and then to TCP or UDP. To TCP: FTP 20 and 21, SSH 22, Telnet 23, SMTP 25, HTTP 80, POP3 110, IMAP 143, HTTPS 443. To UDP: DHCP 67 and 68, TFTP 69, SNMP 161, RIP 520. DNS 53 is joined to both. A dashed line joins HTTPS 443 to UDP as well, for HTTP/3.سێزدە ئەپ، هەریەکەیان بە ژمارەی پۆرتەکەی و پاشان بە TCP یان UDP بەستراوە. بۆ TCP: FTP 20 و 21، SSH 22، Telnet 23، SMTP 25، HTTP 80، POP3 110، IMAP 143، HTTPS 443. بۆ UDP: DHCP 67 و 68، TFTP 69، SNMP 161، RIP 520. DNS 53 بە هەردووکیانەوە بەستراوە. هێڵێکی پچڕپچڕیش HTTPS 443 بە UDPـەوە دەبەستێت، بۆ HTTP/3.
Application → port → transport protocol. ← ← گواستنەوەCêIT

Ports you will meet every dayئەو پۆرتانەی هەموو ڕۆژێک دەیانبینیت

The well-known ports tableخشتەی پۆرتە ناسراوەکان

Checked against the IANA registry, November 2026. IANA registers most of these names for both TCP and UDP; the table shows the protocol the service really uses.لەگەڵ تۆماری بەراورد کراوە، تشرینی دووەمی ⁦2026⁩. زۆربەی ئەم ناوانە بۆ هەردوو و تۆمار دەکات؛ خشتەکە ئەو پیشان دەدات کە خزمەتگوزارییەکە بەڕاستی بەکاری دەهێنێت.
PortTransportگواستنەوەServiceخزمەتگوزاریUsed forبۆ چی
20, 21TCPFTPFile transfer: 21 commands, 20 data (active mode)گواستنەوەی : ⁦21⁩ فەرمان، ⁦20⁩ (شێوازی چالاک)
22TCPSSHSecure remote loginچوونەژوورەوەی پارێزراو لە دوورەوە
23TCPTelnetRemote login without encryption — replaced by SSHچوونەژوورەوە لە دوورەوە بێ — جێی گرتۆتەوە
25TCPSMTPE-mail between mail servers لە نێوان ئیمەیڵدا
53UDP, TCPDNSName lookups (TCP for big answers and zone transfers)گەڕان بە دوای ناودا ( بۆ وەڵامی گەورە و zone transfer)
67, 68UDPDHCP67 server, 68 client: getting an IP address⁦67⁩ ، ⁦68⁩ : وەرگرتنی
69UDPTFTPSimple file transfer, e.g. router imagesگواستنەوەی سادەی ، بۆ نموونە وێنەی سیستەمی
80TCPHTTPWeb pages without encryption بێ
110TCPPOP3Downloading mail ئیمەیڵ
123UDPNTPSetting the clockڕێکخستنی کاتژمێر
143TCPIMAPReading mail on the serverخوێندنەوەی ئیمەیڵ لەسەر
161UDPSNMPMonitoring network devicesچاودێریکردنی ئامێرەکانی
443TCP (UDP for HTTP/3)HTTPSEncrypted web pages
465, 587TCPSMTP submissionYour mail app sends a message to its server ئیمەیڵەکەت نامە دەنێرێت بۆ
520UDPRIPA routing protocol (RIPv2) ⁦(RIPv2)⁩
993TCPIMAPSIMAP over TLS بە سەر
3389TCP, UDPRDPRemote Desktop (a registered port, not well-known)Remote Desktop (، نەک ناسراو)

Sockets and socket pairsسۆکێتەکان و جووتە سۆکێتەکان

An IP address together with a port number is called a socket, written with a colon: 192.0.2.10:49888, or 203.0.113.25:443 for an HTTPS server. Every service has its own port, so each one is its own socket. One conversation has two ends, so it is identified by a socket pair: the protocol, the source IP and port, and the destination IP and port. No two conversations on the Internet have the same socket pair at the same moment. Two hosts may even use the same source port: their IP addresses differ, so the pairs still differ. A home router uses socket pairs to share one public address among all its devices: PAT.

لەگەڵ ژمارەی پێی دەگوترێت و بە دوو خاڵ دەنووسرێت: 192.0.2.10:49888، یان 203.0.113.25:443 بۆ . هەر خزمەتگوزارییەک خۆی هەیە، بۆیە هەریەکەیان خۆیەتی. هەر گفتوگۆیەک دوو سەری هەیە، بۆیە بە جووتێک دەناسرێتەوە: ، IP و سەرچاوە و IP و مەبەست. لە هەمان ساتدا هیچ دوو گفتوگۆیەک لە هەمان جووتە نییە. تەنانەت دوو دەتوانن هەمان سەرچاوە بەکار بهێنن: جیاوازە، بۆیە جووتەکان هێشتا جیاوازن. ماڵەوە بە جووتە یەک ناونیشانی گشتی لە نێوان هەموو ئامێرەکانیدا بەش دەکات: وەرگێڕانی ناونیشانی پۆرت.

Host A, 192.0.2.10, opens two connections from ports 49888 and 49890 to the HTTPS server 203.0.113.25:443. Host B, 198.51.100.7, opens one connection from port 49888 to the web server 203.0.113.80:80. A box lists the three socket pairs: TCP 192.0.2.10:49888 to 203.0.113.25:443; TCP 192.0.2.10:49890 to 203.0.113.25:443; TCP 198.51.100.7:49888 to 203.0.113.80:80. Bottom: hosts A and B both use port 49888, but their IP addresses differ, so the pairs are different; protocol plus source IP and port plus destination IP and port equals one connection.میوانگر A، 192.0.2.10، دوو پەیوەندی لە پۆرتەکانی 49888 و 49890ـەوە بۆ ڕاژەکاری HTTPS 203.0.113.25:443 دەکاتەوە. میوانگر B، 198.51.100.7، یەک پەیوەندی لە پۆرتی 49888ـەوە بۆ ڕاژەکاری وێب 203.0.113.80:80 دەکاتەوە. چوارگۆشەیەک سێ جووتە سۆکێتەکە دەنووسێت: TCP 192.0.2.10:49888 بۆ 203.0.113.25:443؛ TCP 192.0.2.10:49890 بۆ 203.0.113.25:443؛ TCP 198.51.100.7:49888 بۆ 203.0.113.80:80. خوارەوە: میوانگری A و B هەردووکیان پۆرتی 49888 بەکار دەهێنن، بەڵام ناونیشانەکانی IPـیان جیاوازە، بۆیە جووتەکان جیاوازن؛ پرۆتۆکۆڵ و IP و پۆرتی سەرچاوە و IP و پۆرتی مەبەست دەکاتە یەک پەیوەندی.
Same port 49888, different hosts: still two different conversations.هەمان ⁦49888⁩، دوو جیاواز: هێشتا دوو گفتوگۆی جیاوازن.CêIT

Sockets and socket pairsسۆکێتەکان و جووتە سۆکێتەکان

Try it: two sockets in Pythonتاقی بکەرەوە: دوو سۆکێت لە Pythonـدا

Programs use sockets through the operating system. This short Python program starts a tiny TCP server on the loopback address 127.0.0.1, port 50007 (a free test port, as in Python's own documentation), connects a client to it on the same computer and prints both sockets. Python 3.13 printed:

بەرنامەکان لە ڕێگەی بەکار دەهێنن. ئەم بەرنامە کورتەی Python بچووکی لەسەر ⁦127.0.0.1⁩ و ⁦50007⁩ دەکاتەوە ( بەتاڵی تاقیکردنەوە، وەک بەڵگەنامەکانی خودی Python)، لەسەر هەمان کۆمپیوتەر پێیەوە دەبەستێت و هەردوو چاپ دەکات. ⁦Python 3.13⁩ ئەمەی چاپ کرد:

sockets_demo.pyPYTHONType in a terminalلە تێرمیناڵدا بینووسە
import socket, threading

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)    # TCP
server.bind(("127.0.0.1", 50007))      # the server's socket: IP + port
server.listen()
print("server listening on", server.getsockname())

def serve_one():
    conn, peer = server.accept()       # the handshake is finished here
    print("server: connection from", peer)
    conn.sendall(b"hello " + conn.recv(100))
    conn.close()

threading.Thread(target=serve_one).start()

client = socket.create_connection(("127.0.0.1", 50007))
print("client socket:", client.getsockname())   # port chosen by the OS
print("server socket:", client.getpeername())
client.sendall(b"Aram")
print("client got:", client.recv(100).decode())
client.close()
server.close()
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

bind() gives the server its socket: IP 127.0.0.1, port 50007.

bind() دیاری دەکات: ⁦IP 127.0.0.1⁩، ⁦50007⁩.

Lineدێڕی 16

create_connection() runs the three-way handshake; the client's port is chosen by the operating system.

create_connection() ئەنجام دەدات؛ هەڵیدەبژێرێت.

Lineدێڕی 17

Your client port will be different: the operating system picks any free ephemeral port.

تۆ جیاواز دەبێت: هەر بەتاڵ هەڵدەبژێرێت.

One computer with the loopback address 127.0.0.1. Inside it, a client program with socket 127.0.0.1:58491, port chosen by the operating system, and a server program with socket 127.0.0.1:50007 after bind() and listen(). One TCP connection joins them; the client sends b"Aram" and gets "hello Aram". Bottom: the data never leaves the computer; 127.0.0.1 always means this host.کۆمپیوتەرێک بە ناونیشانی خۆگەڕانەوە 127.0.0.1. لە ناویدا بەرنامەیەکی ڕاژەخواز بە سۆکێتی 127.0.0.1:58491 (پۆرتەکەی سیستەمی وەگەڕخەر هەڵیبژاردووە) و بەرنامەیەکی ڕاژەکار بە سۆکێتی 127.0.0.1:50007 دوای bind() و listen(). یەک پەیوەندیی TCP پێکیانەوە دەبەستێت؛ ڕاژەخوازەکە b"Aram" دەنێرێت و "hello Aram" وەردەگرێت. خوارەوە: دراوەکە هەرگیز کۆمپیوتەرەکە بەجێ ناهێڵێت؛ 127.0.0.1 هەمیشە واتە ئەم میوانگرە.
Two sockets, one connection, one computer.دوو ، یەک پەیوەندی، یەک کۆمپیوتەر.CêIT

Demultiplexing: sorting arriving segmentsدیمەڵتیپلێکسکردن: جیاکردنەوەی بڕەکانی گەیشتوو

Sending side: the transport layer accepts data from many programs, labels each piece with its ports and sends everything through one IP address — multiplexing. Receiving side: it reads the destination port in each arriving segment and hands the data to the right program — demultiplexing. In this way TCP and UDP turn one network connection into many logical channels. For UDP the destination port is enough; for TCP the operating system looks at the whole socket pair, because one server port (443) carries many clients at once.

لای نێرەر: لە چەندین بەرنامەوە وەردەگرێت، هەر پارچەیەک بە نیشانە دەکات و هەمووی بە یەک دەنێرێت — . لای وەرگر: مەبەست لە هەر گەیشتوودا دەخوێنێتەوە و دەداتە بەرنامە دروستەکە — . بەم شێوەیە و یەک پەیوەندیی دەکەن بە چەندین کەناڵی مەنتیقی. بۆ مەبەست بەسە؛ بۆ سەیری هەموو جووتە دەکات، چونکە یەک ⁦(443)⁩ لە یەک کاتدا چەندین هەڵدەگرێت.

Animation in five steps. A phone with the IP address 192.0.2.10 runs a browser on TCP port 49731, a mail app on TCP port 49740 and a game on UDP port 50112. Three segments arrive: TCP to 49731, TCP to 49740 and UDP to 50112. The transport layer reads each destination port and sends the first to the browser, the second to the mail app and the third to the game, and a tick appears on each program. Last frame: sending, many programs share one IP — multiplexing; receiving, the port sorts them again — demultiplexing.
Animation in five steps. A phone with the IP address 192.0.2.10 runs a browser on TCP port 49731, a mail app on TCP port 49740 and a game on UDP port 50112. Three segments arrive: TCP to 49731, TCP to 49740 and UDP to 50112. The transport layer reads each destination port and sends the first to the browser, the second to the mail app and the third to the game, and a tick appears on each program. Last frame: sending, many programs share one IP — multiplexing; receiving, the port sorts them again — demultiplexing.
The destination port decides which program gets the segment. مەبەست بڕیار دەدات کام بەرنامە وەردەگرێت.CêIT

Seeing your sockets with netstatبینینی سۆکێتەکانت بە netstat

Windows shows every socket in use with netstat. -n prints numbers instead of names, -a adds the listening ports, and -o adds the process ID (PID) of the program, which you can find in Task Manager. Each line gives the protocol, the local address (your IP and port), the foreign address (the other side's IP and port) and, for TCP, the connection's state. Opening one web page usually creates several TCP connections, each with its own client port.

Windows هەموو کە بەکار دێت بە netstat پیشان دەدات. -n لەبری ناو ژمارە چاپ دەکات، -a ئەو زیاد دەکات کە گوێ دەگرن و -o ناسنامەی پرۆسە ⁦(PID)⁩ی بەرنامەکە زیاد دەکات، کە دەتوانیت لە Task Managerـدا بیدۆزیتەوە. هەر دێڕێک ، ناونیشانی ناوخۆ (IP و تۆ)، ناونیشانی دەرەکی (IP و لایەکەی تر) و بۆ دۆخی پەیوەندییەکە دەدات. کردنەوەی یەک زۆر جار چەند پەیوەندییەکی دروست دەکات، هەریەکەیان بە خۆی.

Part of netstat -ano output on Windows 11 with the columns Proto, Local Address, Foreign Address, State and PID. A LISTENING line: TCP 0.0.0.0:135 to 0.0.0.0:0, PID 1172. A highlighted ESTABLISHED line: TCP 192.0.2.10:49731 to 203.0.113.25:443, PID 8124. Labels under the highlighted line: protocol (TCP or UDP), local socket (my IP : my port), foreign socket (443 = an HTTPS server), TCP state (the connection is open) and process ID (which program, -o). Notes: the LISTENING line is a service waiting for clients; one web page often opens several TCP connections; the addresses are documentation examples.بەشێک لە دەرئەنجامی netstat -ano لەسەر Windows 11 بە ستوونەکانی Proto، Local Address، Foreign Address، State و PID. دێڕێکی LISTENING: TCP 0.0.0.0:135 بۆ 0.0.0.0:0، PID 1172. دێڕێکی ESTABLISHEDـی دیارکراو: TCP 192.0.2.10:49731 بۆ 203.0.113.25:443، PID 8124. لە ژێر دێڕە دیارکراوەکەدا: پرۆتۆکۆڵ (TCP یان UDP)، سۆکێتی ناوخۆ (IPـی من : پۆرتی من)، سۆکێتی دەرەکی (443 = ڕاژەکارێکی HTTPS)، دۆخی TCP (پەیوەندییەکە کراوەیە) و ناسنامەی پرۆسە (کام بەرنامە، -o). تێبینی: دێڕی LISTENING خزمەتگوزارییەکە کە چاوەڕێی ڕاژەخوازەکان دەکات؛ یەک لاپەڕەتۆڕ زۆر جار چەند پەیوەندییەکی TCP دەکاتەوە؛ ناونیشانەکان نموونەی بەڵگەنامەن.
Local socket, foreign socket, state, program. ناوخۆ، دەرەکی، دۆخ، بەرنامە.CêIT
An example on Windows 11 (original, with documentation addresses)نموونەیەک لەسەر ⁦Windows 11⁩ (ڕەسەن، بە ناونیشانی بەڵگەنامە)BATType in a terminalلە تێرمیناڵدا بینووسە
netstat -ano

Two connections (49731 and 49733) go to the same HTTPS server from the same program (PID 8124): one page, two connections. 49740 talks to port 993, IMAP over TLS: a mail app. UDP lines have no foreign address (*:*) and no state, because UDP has no connections. TIME_WAIT and CLOSE_WAIT are stages of closing a TCP connection, explained in TCP states. All the other netstat options are in Windows network commands.

دوو پەیوەندی (⁦49731⁩ و ⁦49733⁩) لە هەمان بەرنامەوە ⁦(PID 8124)⁩ بۆ هەمان دەچن: یەک لاپەڕە، دوو پەیوەندی. ⁦49740⁩ لەگەڵ ⁦993⁩ قسە دەکات، واتە بە سەر : ئیمەیڵ. دێڕەکانی ناونیشانی دەرەکی (*:*) و دۆخیان نییە، چونکە پەیوەندیی نییە. ⁦TIME_WAIT⁩ و ⁦CLOSE_WAIT⁩ قۆناغەکانی داخستنی پەیوەندییەکی و لە دۆخەکانی TCP ڕوون کراونەتەوە. هەموو هەڵبژاردەکانی تری netstat لە فەرمانەکانی ڕایەڵە لە Windowsـدان.

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

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

ExerciseڕاهێنانWhich range?کام بەش؟

Put each port in its range — well-known, registered or dynamic: 25, 443, 1023, 1024, 1883, 3389, 49151, 49152, 50112, 65535.

هەر بخەرە بەشەکەی خۆی — ناسراو، تۆمارکراو یان دینامیکی: ⁦25⁩، ⁦443⁩، ⁦1023⁩، ⁦1024⁩، ⁦1883⁩، ⁦3389⁩، ⁦49151⁩، ⁦49152⁩، ⁦50112⁩، ⁦65535⁩.

Show answerوەڵامەکە پیشان بدە
  • Well-known (0–1023): 25, 443, 1023.
  • Registered (1024–49151): 1024, 1883, 3389, 49151.
  • Dynamic (49152–65535): 49152, 50112, 65535.
  • ناسراو (0–1023): ⁦25⁩، ⁦443⁩، ⁦1023⁩.
  • تۆمارکراو (1024–49151): ⁦1024⁩، ⁦1883⁩، ⁦3389⁩، ⁦49151⁩.
  • دینامیکی (49152–65535): ⁦49152⁩، ⁦50112⁩، ⁦65535⁩.
ExerciseڕاهێنانWrite the socket pairجووتە سۆکێتەکە بنووسە

Dilan's laptop (198.51.100.23) opens a connection to an SSH server at 203.0.113.9; Windows gives it client port 51002. Write the socket pair of the request and of the reply.

دیلان ⁦(198.51.100.23)⁩ پەیوەندییەک بە لە ⁦203.0.113.9⁩ دەکاتەوە؛ Windows ⁦51002⁩ی پێ دەدات. جووتە داواکارییەکە و وەڵامەکە بنووسە.

Hintئاماژە

SSH listens on a well-known TCP port.

لەسەر گوێ دەگرێت.

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

Request: TCP 198.51.100.23:51002 → 203.0.113.9:22. Reply: TCP 203.0.113.9:22 → 198.51.100.23:51002 — the same pair, read from the other end.

داواکاری: TCP، لە ⁦198.51.100.23:51002⁩ـەوە بۆ ⁦203.0.113.9:22⁩. وەڵام: TCP، لە ⁦203.0.113.9:22⁩ـەوە بۆ ⁦198.51.100.23:51002⁩ — هەمان جووت، لە سەرەکەی ترەوە خوێندراوەتەوە.

ExerciseڕاهێنانRead netstatnetstat بخوێنەوە

From the netstat example above: (a) which program has two HTTPS connections? (b) which line shows a service waiting for clients on port 445? (c) why do the UDP lines have no state?

لە نموونەی netstatـی سەرەوە: ⁦(a)⁩ کام بەرنامە دوو پەیوەندیی هەیە؟ ⁦(b)⁩ کام دێڕ خزمەتگوزارییەک پیشان دەدات کە لەسەر ⁦445⁩ چاوەڕێی دەکات؟ ⁦(c)⁩ بۆچی دێڕەکانی دۆخیان نییە؟

Show answerوەڵامەکە پیشان بدە
  • (a) PID 8124, with client ports 49731 and 49733 to 203.0.113.25:443.
  • (b) TCP 0.0.0.0:445 … LISTENING (PID 4, the Windows file-sharing service).
  • (c) UDP is connectionless: there is no connection, so there is no state and no fixed foreign address.
  • ⁦(a) PID 8124⁩، بە ⁦49731⁩ و ⁦49733⁩ بۆ ⁦203.0.113.25:443⁩.
  • (⁦b) TCP 0.0.0.0:445 … LISTENING (PID 4⁩، خزمەتگوزاریی هاوبەشکردنی Windows).
  • ⁦(c)⁩ : هیچ پەیوەندییەک نییە، بۆیە نە دۆخ هەیە و نە ناونیشانی دەرەکیی جێگیر.

Summaryپوختە

  • The IP address finds the host; the 16-bit port number (0–65,535) finds the program.
  • A physical port is a socket for a cable; a logical port is a number in the TCP or UDP header.
  • IANA ranges (RFC 6335): well-known 0–1023, registered 1024–49151, dynamic 49152–65535 (Windows client ports).
  • A socket is IP:port; a socket pair (protocol + both sockets) identifies one conversation.
  • Multiplexing sends many programs through one IP; demultiplexing sorts arriving segments by port. netstat -ano shows it all.
  • دەدۆزێتەوە؛ ژمارەی ⁦16⁩ ⁦(0–65,535)⁩ بەرنامەکە.
  • کونێکە بۆ کێبڵ؛ ژمارەیەکە لە سەردێڕی یان .
  • بەشەکانی ⁦(RFC 6335)⁩: ناسراو ⁦0–1023⁩، تۆمارکراو ⁦1024–49151⁩، دینامیکی ⁦49152–65535⁩ ( Windows).
  • IP:؛ جووتێک ( و هەردوو ) یەک گفتوگۆ دەناسێنێت.
  • چەند بەرنامەیەک بە یەک IPـدا دەنێرێت؛ دیمەڵتیپلێکسکردن گەیشتوو بەپێی جیا دەکاتەوە. ⁦netstat -ano⁩ هەمووی پیشان دەدات.

Next: inside a TCP connection — how the handshake, the windows and the states you saw in netstat work.

دواتر: ناو پەیوەندییەکی TCP — ، و ئەو دۆخانەی لە netstatـدا بینیت چۆن کار دەکەن.

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

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

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

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

Inside a TCP Connection: Handshake, Windows and Reliabilityناو پەیوەندییەکی TCP: سێ ڕێی تەوقەکردن، پەنجەرەکان و پشتپێبەستراوی

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.تەنیا لەسەر ئەم ئامێرە پاشەکەوت دەکرێت.