100% found this document useful (2 votes)
2K views

Chatroom Using Python Project Report

This document describes the development of a basic chatroom application using Python sockets. A server-side script initializes a socket and listens for client connections on a specified port. When a client connects, a new thread is created to handle communication with that client. Clients can connect using a provided client-side script and send messages to each other via the server. The chatroom was tested successfully between two clients connected to the same server. Limitations include only allowing one client to connect at a time and requiring separate server instances for additional clients. Future work could develop an Android app and improve the user interface.

Uploaded by

Ayush Kagane
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
2K views

Chatroom Using Python Project Report

This document describes the development of a basic chatroom application using Python sockets. A server-side script initializes a socket and listens for client connections on a specified port. When a client connects, a new thread is created to handle communication with that client. Clients can connect using a provided client-side script and send messages to each other via the server. The chatroom was tested successfully between two clients connected to the same server. Limitations include only allowing one client to connect at a time and requiring separate server instances for additional clients. Future work could develop an Android app and improve the user interface.

Uploaded by

Ayush Kagane
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Prof.

Ajay K Talele ; Bhagyadeep Jena, Ayush Kagane, Sameer Jamdar, Jason Shaji

ChatRoom
Department of Mechanical Engineering S.Y (2020-21)

Server Side Script

The server side script will attempt to establish a socket and


bind it to an IP address and port specified by the user
Abstract — This article demonstrates How to set up a simple (windows users might have to make an exception for the
Chat Room server and allow multiple clients to connect to it specified port number in their firewall settings, or can rather
using a client side script. The code uses the concept of sockets use a port that is already open). The script will then stay
and threading. open and receive connection requests, and will append
respective socket objects to a list to keep track of active
Keywords —Socket, Multi threading, Client Script, Server Script. connections. Every time a user connects,
INTRODUCTION a separate thread will be created for that user. In each thread,
the server awaits a message, and sends that message to other
Now a days , We all are very active on social media using users currently on the chat. If the server encounters an error
different apps like massager and what's app and with while trying to receive a message from a particular thread, it
keeping this is mind , we have developed an application of will exit that thread.
chatroom on pycharm using python language .
Basically ,this chatroom project is a form of communication Usage
that utilizes computer programs that allow for two - way
conversations between users in real time . Typically , the This server can be set up on a local area network by
users will connect to a chat server using a chat client and choosing any on computer to be a server node, and using
meet in a chatroom . Conversations are then carried on by that computer’s private IP address as the server IP address.
reading the massages entered by the other users in the For example, if a local area network has a set of private IP
chatroom and responding to them . addresses assigned ranging from 192.168.1.2 to
The main aim of this project is to attract the people towards 192.168.1.100, then any computer from these 99 nodes can
a user - friendly interface . We have build a chatroom which act as a server, and the remaining nodes may connect to the
is simple , secure and reliable to massage all the people . We server node by using the server’s private IP address. Care
want to give people better experience of chatting through must be taken to choose a port that is currently not in usage.
this application . For example, port 22 is default for ssh, and port 80 is default
for HTTP protocols. So these two ports preferably, shouldnt
I. METHODOLOGY be used or reconfigured to make them free for usage.
Socket programming However, if the server is meant to be accessible beyond a
local network, the public IP address would be required for
Sockets can be thought of as endpoints in a communication usage. This would require port forwarding in cases where a
channel that is bi-directional, and establishes communication node from a local network (node that isnt the router) wishes
between a server and one or more clients. Here, we set up a to host the server. In this case, we would require any
socket on each end and allow a client to interact with other requests that come to the public IP addresses to be re routed
clients via the server. The socket on the server side towards our private IP address in our local network, and
associates itself with some hardware port on the server side. would hence require port forwarding.
Any client that has a socket associated with the same port
can communicate with the server socket. Below is the Server side script that must be run at all times
to keep the chatroom running.
Multi-Threading

A thread is sub process that runs a set of commands The client side script will simply attempt to access the server
individually of any other thread. So, every time a user socket created at the specified IP address and port. Once it
connects to the server, a separate thread is created for that connects, it will continuously check as to whether the input
user and communication from server to client takes place comes from the server or from the client, and accordingly
along individual threads based on socket objects created for redirects output. If the input is from the server, it displays
the sake of identity of each client. the message on the terminal. If the input is from the user, it
We will require two scripts to establish this chat room. One sends the message that the users enters to the server for it to
to keep the serving running, and another that every client be broadcasted to other users.
should run in order to connect to the server.

This is the client side script, that each user must use in order
to connect to the server.

Output: In the picture given below, a server has been


initialized on the left side of the terminal and a client script
on the right side of the terminal. (Splitting of terminal done
using tmux, ‘sudo apt-get install tmux’). For initialization
purposes, you can see that whenever a message is sent by a
user, the message along with IP address is shown on the
server

A. Testing
The Socket was tested and was found to be in working
condition and it was acting accordingly, and the final Socket
was found to be totally in the working conditions

B. Software used
The whole program is compiled on PyCharm and Run in
PyCharm Console.

II.RESULTS AND DISCUSSIONS

The Socket was tested successfully and the Chatroom was


running Successfully.The Client Script and Server Script
were working in proper conditions and the Connection
between Client and Server established successfully in the
ChatRoom.

III. LIMITATIONS

1. We cannot connect more than one Client to the


Server Script.
2. We have separate Server Script for each Client.
The below picture has a basic conversation between two
people on the same server. Multiple clients can connect to IV. FUTURE SCOPE
the server in the same way!

1. We are going to Develop an actual Android App


using Android Studio.
2. More Graphical interfaces can be added in it.
3. We can use The App to make it more User
Friendly.
V. CONCLUSION SO_REUSEADDR, 1)

hostIp = "127.0.0.1"
portNumber = 7500
1. THE MAIN PURPOSE OF THIS PROJECT IS TO DEVELOP A
SECURE CHAT APPLICATION . clientSocket.connect((hostIp,
portNumber))
2. YOU CAN USE THIS APPLICATION VERY COMFORTABLY
AS WELL AS SMOOTHLY . while True:
clientMessage = input("Client says:
3 . WE HAVE USE PYTHON PROGRAMMING LANGUAGE IN ")
THE CODING OF THIS CHATROOM PROJECT .
clientSocket.send(clientMessage.encode("
utf-8"))
4. BASICALLY , THIS CHATROOM PROJECT PRESENTS A
serverMessage =
SOFTWARE APPLICATION FOR THE LAUNCHING OF A REAL
clientSocket.recv(2048)
TIME COMMUNICATION BETWEEN TWO USERS .
print("Server says: ",
serverMessage.decode("utf-8"))
5 . THIS SYSTEM IS DEVELOPED ON ANDROID WHICH WILL
ENABLE THE USERS TO COMMUNICATE WITH ANOTHER USERS clientSocket.close()
THROUGH TEXT MESSAGES WITH THE HELP OF INTERNET .

Serverside script=from socket import *


6 . SO , WE HAVE TRIED TO MAKE THIS CHATROOM
APPLICATION VERY UNIQUE AS COMPARED TO SOME EXISTING try:
APPLICATIONS hostSocket = socket(AF_INET,
SOCK_STREAM)
.ACKNOWLEDGMENT hostSocket.setsockopt(SOL_SOCKET,
The preferred spelling of the word “acknowledgment” in SO_REUSEADDR,1)
American English is without an “e” after the “g.” Use the hostIp = "127.0.0.1"
singular heading even if you have many acknowledgments. portNumber = 7500
Avoid expressions such as “One of us (S.B.A.) would like to hostSocket.bind((hostIp,
thank .” Instead, write “F. A. Author thanks ..” Sponsor and portNumber))
financial support acknowledgments are placed in the hostSocket.listen()
print ("Waiting for connection...")
unnumbered footnote on the first page.
clientSocket, clientAddress =
hostSocket.accept()
REFERENCES print ("Connection established with:
", clientAddress[0])
1. https://www.tutorialspoint.com/python/python_net while True:
working.htm clientMessage =
clientSocket.recv(2048)
2. https://www.geeksforgeeks.org/simple-chat-room- print ("Client says: ",
using-python/ clientMessage.decode("utf-8"))
serverMessage = input("Server
says: ")
3. https://www.youtube.com/watch?v=u4kr7EFxAKk
clientSocket.send(serverMessage.encode("
4. https://www.youtube.com/watch?v=Lbfe3- utf-8"))
v7yE0&list=PL6yCaejUzyZ3EtSvkwcYK5A3Fj2n hostSocket.close()
1TVmV

except error:
print(error)
CODE:-
Clientside script=from socket import * except KeyboardInterrupt:
print(KeyboardInterrupt)
clientSocket = socket(AF_INET,
SOCK_STREAM)
clientSocket.setsockopt(SOL_SOCKET,

You might also like