Skip to content

Navigation Menu

Sign in
Sign up

Repository files navigation

πŸ”Œ TCP & UDP Socket Programming using Python

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

Niha Hawas

πŸ“„ License

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


Made with ❀️ by Niha Hawas

About

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.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /