Project Report
Project Report
Project File
1. Requirement Analysis:
o Identified the core functionalities needed for a chat
interactions.
3. Server Development:
o Designed the server to act as a central hub for
communication.
o Used Python’s socket module to create a server
socket, listening for incoming client connections on
a specific IP address and port.
o Implemented multithreading to handle multiple
using a socket.
o Enabled real-time sending and receiving of
sessions.
2. Clients:
o Operate independently, sending and receiving
communication.
3. Communication Protocol:
o The server and clients communicate using TCP
port.
o Listens for incoming client connections and spawns
function.
• Client Code:
o Connects to the server socket and establishes a
persistent session.
o Uses separate threads to handle incoming messages
# Server setup
server = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
server.bind(("127.0.0.1", 5555))
server.listen()
clients = []
nicknames = []
# Broadcast function
def broadcast(message):
for client in clients:
client.send(message)
# Accept clients
def receive():
print("Server is running and listening...")
while True:
client, address = server.accept()
print(f"Connected with {str(address)}")
client.send("NICK".encode('utf-8'))
nickname = client.recv(1024).decode('utf-8')
nicknames.append(nickname)
clients.append(client)
thread = threading.Thread(target=handle_client,
args=(client,))
thread.start()
receive()
Client Code
import socket
import threading
client = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
client.connect(("127.0.0.1", 5555))
# Receive messages
def receive():
while True:
try:
message = client.recv(1024).decode('utf-8')
if message == "NICK":
client.send(nickname.encode('utf-8'))
else:
print(message)
except:
print("An error occurred!")
client.close()
break
# Send messages
def write():
while True:
message = f"{nickname}: {input('')}"
client.send(message.encode('utf-8'))
write_thread = threading.Thread(target=write)
write_thread.start()
Detailed Explanation
• Socket Creation: Sockets are created using the socket
module to enable communication.
• Thread Management: Each client connection is handled
in a separate thread to allow simultaneous
communication.
• Message Encoding and Decoding: Messages are
encoded before transmission and decoded upon receipt to
ensure compatibility.
Tools and Technologies
1. Programming Language:
o Python: Used for its simplicity and extensive library
tasks.
3. Integrated Development Environment:
o PyCharm: Provides an efficient platform for code
interactions.
o Basic network connection for all the basic server
multiple clients.
3. Performance Testing:
o Measured message latency and resource utilization