Computer Networks - Mini Project
Computer Networks - Mini Project
Sathya.C - 710622104075
Sandhiya.J - 710622104071
Mithun.G - 710622104046
Balakamatchi.S – 710622104007
Abstract
This mini project demonstrates a simple Local Area Network (LAN) chat
application built using Python's socket programming. It allows multiple
clients to connect to a central server and exchange text messages in real
time. The server handles multiple client connections, broadcasting each
client's message to others. The project illustrates fundamental client-server
communication in a networked environment, offering a practical introduction
to network programming and multithreading.
Introduction
Communication over a network has become an essential part of modern
computing. Whether through messaging apps, email, or other forms of
communication, the principles of sending and receiving data over a network
are fundamental. In this project, a basic LAN chat system is developed to
facilitate real-time communication between clients within a local network. By
employing Python’s socket library and threading capabilities, this chat
application allows multiple users to send and receive messages
simultaneously in a non-blocking manner.
This project focuses on implementing the client-server architecture. The server
listens for connections from clients, receives messages, and forwards them to
all connected clients. The clients connect to the server and participate in a
chat session by sending and receiving messages.
Software Requirements
Close client
Server Code: server.py
import socket
import threading
# Function to broadcast message to all clients
# Function to handle client connections def broadcast_message(message, client_socket,
def handle_client(client_socket, clients): clients):
while True: for client in clients:
try: if client != client_socket:
# Receive message from the client try:
message = client_socket.recv(1024).decode('utf-8') client.send(message.encode('utf-8'))
if message: except:
print(f"Received: {message}") remove_client(client, clients)
broadcast_message(message, client_socket,
clients) # Function to remove disconnected client
else: def remove_client(client_socket, clients):
remove_client(client_socket, clients) if client_socket in clients:
break clients.remove(client_socket)
except: client_socket.close()
continue
Server Code: server.py
while True:
# Main function to run the server client_socket, client_address =
def start_server(): server.accept()
server = socket.socket(socket.AF_INET, print(f"Connection established with
socket.SOCK_STREAM) {client_address}")
server.bind(('0.0.0.0', 5555)) clients.append(client_socket)
server.listen(5)
print("Server started. Waiting for threading.Thread(target=handle_client,
connections...") args=(client_socket, clients)).start()
Client Side
Server Side
Conclusion
This mini-project demonstrates the practical implementation
of a simple LAN-based chat system. It introduces core
concepts in socket programming, client-server
communication, and multithreading. By following the project,
students and developers gain a hands-on understanding of
how data is transmitted between computers over a network.
The system, though basic, can be expanded to include
additional features such as encryption, user authentication,
and improved message formatting. Through this project, we
see how communication applications like chat apps are
developed and the principles behind networking.
Thank You