Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
129 views

Computer Networks - Mini Project

computer networks project
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
129 views

Computer Networks - Mini Project

computer networks project
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

CSI College of Engineering, Ketti

Simple LAN Chat


Mini PROJECT

Subject Title: Computer Networks


Subject Code: CS3591
Dept / Year: CSE / 3RD YEAR
Team Members
Fiza.F - 710622104015

Sathya.C - 710622104075

Sandhiya.J - 710622104071

Mithun.G - 710622104046

Anish Kumar.A - 710622104006

Manoj Kumar.M - 710622104043

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

1. Python 3: The programming language used to


develop the project.
2. Text Editor/IDE: (e.g., VS Code, PyCharm, Sublime
Text) for writing and editing the code.
3. Socket Library: Python's built-in library to implement
network communication.
4. Threading Library: Python’s threading library for
handling multiple clients simultaneously.
5. Operating System: Any operating system that
supports Python (Linux, Windows, macOS).
Hardware Requirements
Hardware:
1. Computer Systems: At least two machines (can be
virtual machines or physical computers) for client-
server communication.
2. Network Interface: LAN or Wi-Fi network for
establishing communication between devices.
3. Router/Switch: For connecting all the clients and
server in a Local Area Network (optional, if devices
are on different network subnets).
Flowchart Start the server

Listen for clients

Accept client Broadcast message


to all clients

Receive Message Client Sends


message

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()

clients = [] if __name__ == "__main__":


start_server()
Client Code: client.py
# Main function for client
import socket def start_client():
import threading client = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
# Function to receive messages from the server server_ip = input("Enter server IP address: ")
def receive_messages(client_socket): client.connect((server_ip, 5555))
while True:
try: print("Connected to the server!")
message =
client_socket.recv(1024).decode('utf-8') threading.Thread(target=receive_messages,
if message: args=(client,)).start()
print(f"\n{message}")
else: while True:
break message = input()
except: client.send(message.encode('utf-8'))
break
if __name__ == "__main__":
start_client()
To Run the code

We first run the server.py file so that the sever finds


its connection.
Server code:
python server.py

To connect the client to the server we run the


client.py and input the IP address of the server
Client code:
python server.py
Code implementation
Code implementation
Connecting to the server
Input Output
Output

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

You might also like