









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to LetsChat, a simple Python group chat server. It includes a tutorial on installing the application, setting up the server and client, and API reference. The server uses multiple threads to handle client communication and broadcast messages to all connected clients.
Typology: Lecture notes
1 / 17
This page cannot be seen from the preview
Don't miss anything!










ii
LetsChat is a simple python group chat server. It is similar in application to any ordinary chat server except that this application can be used only for the purpose of chatting in a group which means we cannot use this application for the purpose of chatting one-to-one. It is a console based application.
This tutorial will show you how to set up both the server and the client.
There are 2 pre-requisites for installing the application.
The entire project is uploaded on github.
To start the server go to the source directory present in the root directory. Then execute the following command on the command prompt on your Windows machine or the terminal on your Linux/Max machines.
pip install requirements.txt
LetsChat Documentation, Release 0
Once you are through with installing all necessary modules you should be okay to start the server. The server runs on port 1337 so its important that this port is free. To check that no process is currently active in port 1337 execute the following command on the command prompt on your Windows machine.
netstat -a
The above command will show all process running on all ports available on the machine. If port 1337 is not shown, it means that the port is not currently running any process.
On Linux/Mac you can check the ports running on the local machine using the following terminal command.
netstat -pnlt | grep ':1337'
If there are any processes running on port 1337, we would need to kill that process before starting the server. Once you are reaady to start the server, head over to the source directory inside the root directory. Next go inside the server directory present in the source directory. Then execute the following command on the command prompt on your Windows machine or the terminal on your Linux/Max machines. T
python serverSocket.py
With this command the server should be started on your local machine and listening on port 1337.
If you are a client and would like to start a group chat or get involved in an existing group chat, you will be required to connect to the server through port 1337. Make sure that the port is not blocked by another process. To check for processes running on port 1337 follow the procedure listed above.
Once you are ready to connect to the server head over to the Client directory inside source. Now execute the following command in the command prompt of your Windows machine or in the terminal of your Linux/Mac machine.
python clientSocket.py
Now the client should be connected to the server. Now you can exchange messages with other clients on the network.
4 Chapter 2. Tutorial
LetsChat Documentation, Release 0
init (self, threadID, name, counter, clientSocket, allClients) This init method overrides the init function of the Thread class in the threading module. It calls the init function to actually create an instance of the Thread class. It then initializes other variables to be required by the thread. Parameters
3.2 Client
class writingThread. WritingThread The WritingThread is a thread class. Its instance is created as a thread that is spawned by the clientSocket module for sending data from the client to the server. It reads data from the standard input and sends it to the server. init (self, threadID, name, counter, clientSocket) This init method overrides the init function of the Thread class in the threading module. It calls the init function to actually create an instance of the Thread class. It then initializes other variables to be required by the thread. Parameters
class readingThread. ReadingThread The ReadingThread is a thread class. Its instance is created as a thread that is spawned by the clientSocket module. init (self, threadID, name, counter, clientSocket) This init method overrides the init function of the Thread class in the threading module. It calls the init function to actually create an instance of the Thread class. It then initializes other variables to be required by the thread. Parameters
6 Chapter 3. API Reference
LetsChat Documentation, Release 0
3.2. Client 7
LetsChat Documentation, Release 0
10 Chapter 4. Indices and tables
LetsChat Documentation, Release 0
12 Python Module Index
Index
Symbols
init() (clientThread.ClientThread method), 5 init() (clientThreadReadHan- dle.ClientThreadReadHandle method), 5 init() (readingThread.ReadingThread method), 6 init() (writingThread.WritingThread method), 6
C
clientSocket (module), 6 ClientThread (class in clientThread), 5 clientThread (module), 5 ClientThreadReadHandle (class in clientThreadReadHan- dle), 5 clientThreadReadHandle (module), 5
R
ReadingThread (class in readingThread), 6 readingThread (module), 6 run() (clientThread.ClientThread method), 5 run() (clientThreadReadHan- dle.ClientThreadReadHandle method), 6 run() (readingThread.ReadingThread method), 7
S
serverSocket (module), 5
W
WritingThread (class in writingThread), 6 writingThread (module), 6