TCP, UDP and Sockets
Quick answer
A socket is an operating-system communication endpoint. TCP provides a reliable ordered byte stream; UDP provides datagrams without built-in delivery guarantees.
Prepare the practice environment
Run python3 lab-fixtures/networking/setup.py from the extracted package root as an ordinary user. Enter the printed private path and check pwd. Use a fresh fixture, Bash with LC_ALL=C and set -o pipefail. Python 3 is required for the fixed local socket helper. Use only loopback or synthetic data; never apply sample configuration. Manual examples require an authorized disposable VM.
How it works
Ports identify transport endpoints in context of protocol, addresses and namespace. TCP establishes connections; a listening socket waits for new ones. UDP preserves datagram boundaries but applications must handle loss, duplication or reordering if relevant. ss -ltn selects listening TCP sockets with numeric addresses; -lun selects listening/unconnected UDP sockets. A loopback-bound service is not normally exposed on external interfaces; 0.0.0.0 is a wildcard bind, not a remote destination. A listening socket does not prove firewall or application health.
Do not count calls to send and receive as if they were messages in TCP. Two writes can be read together, or a single write can require multiple reads. Define application framing, such as a delimiter or a length field. UDP retains datagram boundaries; a receive buffer that is too small can truncate a datagram. In the local exercise, verify the expected bytes, not just that a socket exists.
Try the examples
These rows are simplified, not raw ss output.
Expected stdout:
tcp LISTEN 127.0.0.1:8080udp UNCONN 127.0.0.1:5353The helper binds an OS-selected loopback port, checks only that port in ss and closes the socket.
Expected stdout:
own TCP listener foundOne successful datagram demonstrates local delivery, not a general reliability guarantee.
Expected stdout:
received: helloCommon mistakes
Do not expose a lab server on 0.0.0.0 or assume UDP is always faster or TCP message boundaries are preserved.
Practice
Explain which fictional socket is TCP, which is UDP, and why neither row proves external reachability.
Related references
Study: ss. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
TCP, UDP and sockets — Knowledge Check
Apply network concepts to loopback, synthetic fixtures and VM-only scenarios.
TCP delivers what abstraction?
What does UDP preserve?
Which address limits a lab to IPv4 loopback?
Which ss option selects TCP?