This repository contains tiny Python exercises that demonstrate how TCP and UDP work in practice. They’re simple enough to run locally and are a great way to understand the difference between reliable (TCP) and fast but unreliable (UDP) communication.
tcp_server.py
→ Simple TCP servertcp_client.py
→ Simple TCP clientudp_server.py
→ Simple UDP serverudp_client.py
→ Simple UDP client
git clone https://github.com/dre86dre/TCP-UDP-Python-Examples.git
In one terminal, start the server:
cd tcp_example
python tcp_server.py
In another terminal, run the client:
python tcp_client.py
You should see:
Server side → Received: Hello TCP Server!
Client side → Server says: Hello from TCP server!
✅ Messages are delivered reliably and in order.
In one terminal, start the server:
cd udp_example
python udp_server.py
In another terminal, run the client:
python udp_client.py
You should see:
Server side → Received: Hello UDP Server! from ('127.0.0.1', <random_port>)
Client side → Server says: Hello from UDP server!
- Reliable, ordered, error-checked communication.
- Used for web browsing, emails, file downloads.
- Faster, lightweight, no guarantees.
- Used for video calls, online gaming, streaming.
- Python 3.x
- Works on Linux, macOS, or Windows
No external dependencies are needed.
This project is licensed under the MIT License.