โ— Shell
clean mode source โ†—

GitHub - nihahawas/Socket-Programming-Python: A Python-based Socket Programming project implementing both TCP and UDP communication using client-server architecture. This project demonstrates reliable and connectionless data transmission, message exchange, and basic networking concepts using Python sockets in Jupyter Notebook or VS.

Python Socket Status License

A complete implementation of Client-Server Communication using Python's built-in socket library โ€” covering both TCP and UDP protocols with real-time bidirectional messaging.


TCP Server and Client communication

tcp-server-client

๐Ÿ“Œ About This Project

This project demonstrates real-time Client-Server Communication using Python sockets. It implements both TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) with features like timestamps, uppercase conversion, message counting, and graceful exit handling.


๐Ÿ“ File Structure

Socket-Programming-Python/
โ”‚
โ”œโ”€โ”€ tcp_server.py       # TCP Server Program
โ”œโ”€โ”€ tcp_client.py       # TCP Client Program
โ”œโ”€โ”€ udp_server.py       # UDP Server Program
โ”œโ”€โ”€ udp_client.py       # UDP Client Program
โ””โ”€โ”€ README.md           # Project Documentation

โœจ Features

  • โœ… TCP Client-Server Communication
  • โœ… UDP Client-Server Communication
  • โœ… Student Name & Registration Number on startup
  • โœ… Timestamp on every message [HH:MM:SS]
  • โœ… Messages automatically converted to UPPERCASE
  • โœ… Message counter (tracks total messages sent)
  • โœ… Type exit to gracefully end the session

๐Ÿ”„ TCP vs UDP

Feature TCP UDP
Connection Required Not Required
Reliability High โœ… Low โš ๏ธ
Speed Slower Faster โšก
Data Order Guaranteed Not Guaranteed
Port Used 12345 12346
Real-world Use HTTP, FTP, Email Streaming, Gaming, DNS

๐Ÿš€ How to Run

Prerequisites

python --version   # Make sure Python 3.x is installed

โ–ถ๏ธ TCP Communication

Open two terminals simultaneously:

# Terminal 1 โ€” Run Server FIRST
python tcp_server.py

# Terminal 2 โ€” Run Client SECOND
python tcp_client.py

โ–ถ๏ธ UDP Communication

# Terminal 1 โ€” Run Server FIRST
python udp_server.py

# Terminal 2 โ€” Run Client SECOND
python udp_client.py

โš ๏ธ Always start the Server before the Client!


๐Ÿ’ฌ Sample Output

========================================
        UDP SERVER STARTED
  Student : Niha Hawas
========================================
Listening on 127.0.0.1:12346 ...
Waiting for messages...

[20:24:28] Client [1]: HELLO
  โ”” UPPERCASE: [NIHA HAWAS | 2312274] CLIENT: HELLO
Your Reply: HI

[20:24:46] Client [2]: HAVE YOU DONE YOUR TASK
  โ”” UPPERCASE: CLIENT: HAVE YOU DONE YOUR TASK
Your Reply: YES IT IS DONE

โœ… UDP Server closed. Total messages handled: 7

๐Ÿ“‹ Tasks Completed

# Task Status
1 TCP Server and Client communication โœ…
2 UDP Server and Client communication โœ…
3 Exchange at least 5 messages โœ… (7 messages)
4 Send Student Name and Registration Number โœ…
โญ Timestamps on every message โœ…
โญ Convert messages to UPPERCASE โœ…
โญ Terminate session with exit command โœ…

๐Ÿ› ๏ธ Technologies Used

Tool Purpose
Python 3.x Core Language
socket module Network Communication
VS Code Development Environment
GitHub Version Control

๐Ÿ“š Concepts Covered

  • Client-Server Architecture
  • TCP โ€” Connection-Oriented Communication
  • UDP โ€” Connectionless Communication
  • Socket Binding, Listening & Accepting
  • Real-time Bidirectional Messaging
  • Data Encoding & Decoding over Sockets

๐Ÿ‘ฉโ€๐Ÿ’ป Author


๐Ÿ“„ License

This project is licensed under the MIT License โ€” feel free to use and modify.


Made with โค๏ธ by Niha Hawas