A real-time chat application built with Python, featuring both TCP and UDP communication protocols with a modern graphical user interface.
This is a project related to CSCI 21023 - Data Communication and Networks. The application demonstrates socket programming concepts with a client-server architecture that supports both reliable (TCP) and unreliable (UDP) communication protocols.
- Dual Protocol Support: Switch between TCP and UDP messaging seamlessly
- Real-time Messaging: Instant message delivery across connected clients
- Modern GUI: Clean, WhatsApp-inspired interface built with CustomTkinter
- Multi-client Support: Server handles multiple simultaneous connections
- Thread-safe Operations: Proper synchronization for concurrent message handling
- Message Deduplication: UDP messages are filtered to prevent echoes
- Auto-reconnection: Visual status indicators with reconnection capability
- TCP Server: Listens on port 8888 for persistent client connections
- UDP Server: Listens on port 9999 for connectionless messaging
- Broadcasting: Messages are relayed to all connected clients
- Thread Management: Each TCP client is handled in a separate thread
- Client Management: Automatic cleanup of disconnected clients
- TCP Connection: Reliable stream-based communication
- UDP Socket: Shared, thread-safe UDP socket with automatic registration
- Message Deduplication: Prevents receiving own UDP messages
- Background Listeners: Separate threads for TCP and UDP message reception
- CustomTkinter GUI: Modern, responsive chat interface
- Protocol Toggle: Switch between TCP and UDP modes
- Message Bubbles: Visual distinction between sent and received messages
- Error Handling: User-friendly error dialogs and status indicators
- Async Connection: Non-blocking server connection with status updates
pip install customtkinter- Navigate to the server directory:
cd server- Run the server:
python main.pyThe server will start listening on:
- TCP:
0.0.0.0:8888 - UDP:
0.0.0.0:9999
- Update server IP in
client/connection.py:
server_ip = "YOUR_SERVER_IP"
server_port = 8888
udp_port = 9999- Navigate to the client directory:
cd client- Run the client:
python main.py-
TCP Mode (Default):
- Type your message in the input field
- Press Enter or click "Send"
- Message is reliably delivered to all connected clients
-
UDP Mode:
- Click the "TCP" button to switch to "UDP"
- Type and send messages
- Messages are prefixed with
[UDP]tag - Delivery is not guaranteed but faster
- Yellow "Connecting...": Initial connection attempt
- Green "Connected": Successfully connected to server
- Red "Disconnected, Retry?": Connection failed (click to retry)
- Green bubbles (right): Your sent messages
- White bubbles (left): Received messages from others
- Red bubbles (center): Error messages
- Client establishes connection with server
- Server adds client to active connections list
- Messages are sent to server via
send_message() - Server broadcasts to all other connected clients
- Clients receive via
receive_message()callback
- Client creates/reuses shared UDP socket
- Registration message sent to server on first use
- Server tracks UDP client addresses
- Messages include unique timestamp ID
- Clients filter out their own messages using ID matching
- No delivery guarantee or ordering
handle_client(): Manages individual TCP connectionsudp_echo(): Broadcasts UDP messages to registered clientstcp_server(): Accepts new TCP connectionsudp_server(): Listens for UDP datagrams
_get_udp_socket(): Singleton pattern for UDP socket_SocketProxy: Delayed socket initialization for UI responsivenessadd_message_to_ui(): Thread-safe UI updatessend_button_click(): Protocol-aware message sending
- Connection Failures: Graceful error dialogs with retry option
- Broken Pipes: Automatic client cleanup on disconnection
- Thread Safety: Locks prevent race conditions in UDP socket access
- Message Send Failures: Error bubbles displayed in chat
Socket_Programming_Project/
โโโ README.md
โโโ client/
โ โโโ connection.py # Network communication logic
โ โโโ main.py # GUI application
โ โโโ __pycache__/
โโโ server/
โโโ main.py # Server implementation
- No encryption (messages sent in plaintext)
- No authentication or authorization
- No input validation or sanitization
- Public IP exposure in code
For production use, implement:
- TLS/SSL encryption
- User authentication
- Input validation
- Rate limiting
- Secure configuration management
- UDP message deduplication clears all IDs after 100 messages (memory optimization)
- Server IP is hardcoded in
connection.py - No persistent message history
- No file transfer support
This is an academic project. Feel free to fork and extend for learning purposes.
Educational project for CSCI 21023 course.
Socket Programming Project Team
Chamesh Dinuka
Kisara Beddawala
Sanjana Kaushalya
- CSCI 21023 - Data Communication and Networks course
- CustomTkinter library for modern UI components
- Python socket programming documentation