Similar to Network Programming in Python with the help of socket concept. A simple exercise to demonstrate the working of network communication through sockets.
Socket
A socketis an endpoint of a two-way communication link between
two programs running on a network.
It allows data to be sent and received between devices, just like
plugging a cable into a port.
Sockets are the foundation of network programming in Python.
Socket programming in Python involves using sockets to establish
communication between a server and clients over a network.
Stream Socket (TCP)
•UsesTransmission Control Protocol
•Connection-oriented
•Reliable delivery (data reaches in order, without loss)
•Used for: web servers, chat applications, file transfer
7.
Datagram Socket (UDP)
•UsesUser Datagram Protocol
•Connectionless
•Faster but not reliable
•Used for: gaming, video streaming, real-time updates
Low-Level Networking (Socket
Layer)
At the foundational level, Python gives direct access to the
operating system’s socket interface.
With this, you can manually build networking applications by
controlling every detail of the connection.
This level allows you to create both:
1. Connection-oriented communication (e.g., TCP)
2. Connectionless communication (e.g., UDP)
In this layer, you work with raw sockets, manage IP addresses and
ports yourself, and handle sending/receiving data packets directly.
10.
High-Level Networking (Protocol
Libraries)
Above the socket layer, Python provides modules that implement
common internet protocols for you.
Instead of managing sockets manually, you can directly use ready-
made tools to interact with:
1. HTTP (via urllib, requests)
2. FTP (via ftplib)
3. SMTP (via smtplib)
4. And other application-level protocols
This layer simplifies tasks like downloading web pages, sending
emails, or transferring files because it hides the low-level socket
operations behind user-friendly APIs.
How to Run?
1.Save both codes in two files:
server.py
client.py
2. Run server:
python server.py
3. Run client (in another terminal):
python client.py
4. You will see messages exchanged between server and client.
15.
Simple Python SocketProgramming Exercises
Exercise 1: Print a Message from Client to Server
Exercise 2: Send Your Name to the Server
Exercise 3: Two-Number Addition