TP3 M1 RSD - Advanced Networks 1
Socket Programming Labs – Python Client/Server and Multithreading
Lab 1 — Introduction to Sockets (Client Basics)
Objectives
- Understand what a socket is.
- Create and connect to a TCP server.
- Send and receive simple text messages.
Tasks
- Create a TCP socket and connect to [Link].
- Send an HTTP GET request.
- Receive the first 1024 bytes and print the response.
Questions
- What is AF_INET vs SOCK_STREAM?
- What happens if the port is closed?
- Why do we use encode()?
Lab 2 — Simple TCP Server (One Client Only)
Objectives
- Create a server that listens on a port.
- Accept only one connection.
- Send and receive simple messages.
Tasks
- Bind to [Link]:5000 and listen.
- Accept one client and print 'Client connected'.
- Receive a message and reply 'Message received'.
Questions
- Why is accept() called once?
- What happens if another client tries to connect?
- Why loops are needed for multi-client servers?
Lab 3 — Multithreading TCP Server
Objectives
- Handle multiple clients simultaneously.
- Use threads to avoid blocking.
Tasks
- Listen on port 5000.
- Create a new thread for each client.
- Echo messages until client sends 'bye'.
Questions
- What problem does multithreading solve?
- Does a slow client block others?
- Draw the accept() threading diagram.
Lab 4 — Packet Capture and Analysis (Wireshark)
Objectives
- Visualize TCP handshake.
- Analyze client/server packets.
Tasks
- Run server and capture traffic.
- Find SYN, SYN/ACK, ACK.
- Observe data and FIN packets.
Questions
- Difference between TCP segment and application message?
- Why can messages be split?