HNA CyberClub · interactive briefing · Part 02

Applications communicate
through sockets.

See how the operating system connects processes to TCP, UDP and port numbers.

Δες πώς το λειτουργικό σύστημα συνδέει τις διεργασίες με το TCP, το UDP και τα port numbers.

Hover or focus for Greek
Explore the sections ↓
Section 01

Operating systems and protection

The operating system manages CPU time, memory, files and devices. Ordinary applications run in user space. The kernel executes privileged operations and controls critical resources.

Το λειτουργικό σύστημα οργανώνει CPU, μνήμη, αρχεία και συσκευές. Οι συνηθισμένες εφαρμογές εκτελούνται στο User Space. Ο kernel εκτελεί προνομιούχες λειτουργίες και ελέγχει κρίσιμους πόρους.

Hover or focus for Greek
An application requests a service from the OSUSER / KERNEL

User Space

Python clientFirefoxText editor

Python calls send() on its socket.

API / system calls · service request

Kernel Space

The TCP/IP stack manages the socket, buffers and packets.

Hardware

The network adapter handles transmission. For localhost, the path stays inside the OS.

Simplified Windows/Linux model. The spaces represent protection and access, not two separate computers. Library/API calls may use system calls.

Section 02

A program runs as a process

A process is a running instance of a program with its own state and resources. The OS assigns it a process ID. An application such as Firefox may use several processes.

Μια διεργασία είναι μια εκτέλεση προγράμματος με δική της κατάσταση και πόρους. Το OS της δίνει έναν Process ID (PID). Μια εφαρμογή, όπως ο Firefox, μπορεί να χρησιμοποιεί πολλές διεργασίες.

Hover or focus for Greek
A small process managerTEACHING SIMULATION

PID values are illustrative. These buttons change only this example.

ProgramPIDStateAction

Each active process has its own PID within this OS.

After a process ends, the OS may reuse its PID later. Two different PCs can have the same PID at the same time.

Section 03

A socket is a communication endpoint

An application requests a socket from the OS and uses a handle or file descriptor to access it. The kernel keeps its state and buffers. One process may use many sockets.

Η εφαρμογή ζητά ένα socket από το λειτουργικό και το χρησιμοποιεί μέσω ενός handle ή file descriptor. Ο kernel διατηρεί την κατάσταση και τα buffers του. Μία διεργασία μπορεί να χρησιμοποιεί πολλά sockets.

Hover or focus for Greek
The life of a TCP server socketSTEP 0 / 5

User Space

Python server · PID 4100

# The server does not have a socket yet

S1 and S2 are symbolic socket names, not port numbers.

Kernel Space

No socket in this example yet.

Select Next step to let Python request a TCP socket.

Section 04

IP, port and PID: different roles

IP supplies a network address. Ports are 16-bit fields in TCP/UDP headers. The OS uses endpoint information to find a socket. A PID identifies a process inside the OS and is not carried in the TCP/UDP header.

Η IP δίνει διεύθυνση δικτύου. Τα ports είναι αριθμοί 16 bit στις επικεφαλίδες TCP/UDP. Το OS χρησιμοποιεί τα στοιχεία των άκρων για να βρει socket. Το PID αναγνωρίζει τη διεργασία μέσα στο OS και δεν βρίσκεται στην επικεφαλίδα TCP/UDP.

Hover or focus for Greek

IP address

127.0.0.1

A network address. Here it refers to this same PC.

Port number

8000 / TCP

Part of the information identifying a communication endpoint.

Process ID

PID 4100

A process identifier local to the OS.

Where will the kernel deliver the data?SOCKET LOOKUP

Information on the network

Source IP127.0.0.1
Destination IP127.0.0.1
Source port62609
Destination port8000
Transport protocolTCP

In this TCP example, the connection to port 8000 has already completed its handshake.

Mappings inside the OS

SocketLocal endpointProcess
S2TCP :8000Server
PID 4100
U1UDP :8000Telemetry
PID 6200

S2 has remote endpoint 127.0.0.1:62609. Listening socket S1 (also TCP :8000, see Section 05) is omitted here: a new connection request (SYN) to port 8000 would be matched to S1, while data on this established connection is matched to S2. There is no socket for port 9000 in this example.

Try TCP and UDP with the same destination port, 8000.

Why is the port alone not enough?

A TCP connection is distinguished by source IP, source port, destination IP and destination port. UDP has a separate port space and different matching rules. Here we use a simple case with one receiver per protocol.

Port values range from 0 to 65535. In many bind() calls, a value of 0 asks the OS to choose a port automatically.

Section 05

One server port, multiple TCP connections

A server creates a listening socket. For each accepted connection, accept() returns a new socket. The listening socket keeps waiting and the server port remains 8000.

Ο server δημιουργεί ένα listening socket. Για κάθε αποδεκτή σύνδεση, το accept() επιστρέφει ένα νέο socket. Το listening socket συνεχίζει να περιμένει και το server port παραμένει 8000.

Hover or focus for Greek
Server PID 4100 · TCP 127.0.0.1:80000 CONNECTIONS

S1 · LISTEN

Local endpoint: 127.0.0.1:8000 · waiting for new connection requests

New server socketClient endpointServer endpoint
No established connection yet.

Connect two clients and compare their ports.

Client ports here are consecutive for readability. Real systems pick temporary (ephemeral) ports with randomization: Windows uses 49152–65535 by default and Linux 32768–60999, so your own captures will show different numbers.

TCP

A connection with reliable, ordered delivery of a byte stream. One send() does not necessarily correspond to one recv(). The application defines the boundaries of its own messages.

UDP

Separate datagrams without a TCP handshake. A UDP socket can receive messages from multiple senders, usually with recvfrom(). UDP does not guarantee delivery or ordering.

UDP also has a connect() API, without a TCP handshake.

Section 06

Our HTTP lab, step by step

Client and server can run on the same PC. Both endpoints use 127.0.0.1 but different ports. HTTP is the application data carried by TCP.

Ο client και ο server μπορούν να βρίσκονται στο ίδιο PC. Και τα δύο άκρα έχουν IP 127.0.0.1, αλλά διαφορετικά ports. Το HTTP είναι τα δεδομένα της εφαρμογής που μεταφέρει το TCP.

Hover or focus for Greek
Python client · 62609 ⇄ Python server · 8000LOCALHOST
Source endpoint—
Destination endpoint—
TCP / HTTPReady for connect()

Move through the steps. PIDs do not appear in network header fields.

Teaching sequence. A real capture may combine data and flags into a different number of packets, and it will also show FIN/ACK segments when the connection closes. A TCP ACK acknowledges bytes, not whether the file exists.

Section 07

From Wireshark to the process

Wireshark shows addresses, ports and data. OS tools show which process owns the connection. Combine these two views while the Python server is running.

Το Wireshark δείχνει διευθύνσεις, ports και δεδομένα. Τα εργαλεία του OS δείχνουν ποια διεργασία χρησιμοποιεί τη σύνδεση. Συνδύασε τις δύο όψεις με ενεργό τον Python server.

Hover or focus for Greek

1. Wireshark

For the localhost kit, capture on the Adapter for loopback traffic capture.

tcp.port == 8000

Find the destination port in the GET and the source port in the response.

2. Windows PowerShell

Get-NetTCPConnection -LocalPort 8000

Note the OwningProcess and substitute its number for <PID>:

Get-Process -Id <PID>

-LocalPort 8000 lists the server side, so OwningProcess is the server's PID. To find the client process, use Get-NetTCPConnection -RemotePort 8000.

HTTP 404 means the application responded with “not found”. TCP may still have successfully carried that entire response.
Sources and further details