Skip to content

nihahawas/Socket-Programming-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages