This is a socket-based multi-threaded chat application.
The Chat Application will be hosted on your local host! All you need to install is Docker Engine and Docker Compose.
Ensure that your docker engine is running. From the top level directory of this git repository run the following command:
docker-compose up -d
This command will build the images of all the application services and it will launch all the services. Once you have your containers running, you want to start the server and client applications.
To start the server, login to the server container as follows and run the server program.
docker exec -it chat_app_websocket /bin/sh
python3 server.py 5200
After this, login to the client container and start the client program(s).
docker exec -it chat_app_client /bin/sh
python3 client.py 5200
You can launch as many client programs as you want as this is a multi-party chat application.
To stop the application and delete all the containers:
docker-compose down
To temporarily stop the application, but keep the containers and their associated data:
docker-compose stop
The following diagram shows a high-level architecture of the application components.
- When a client starts the application, it talks to the web service to authenticate user credentials, join new rooms or view older messages. The webserver exposes REST APIs to the client to allow this to happen.
- When the client requests to join a chat room, it talks to the websocket server. The websocket server executes a handshake protocol to identify the client. Upon identification, the websocket server lets the client into the requested chat room by launching a dedicated thread for the client.
- The websocket server has a dedicated thread for each client, performing socket I/O. This allows the websocket server to achieve concurrency by interleaving I/O bound operations with CPU bound operations.
- The websocket server broadcasts the chat room's messages in real-time to all the clients present in the chat room.
- The websocket server also stores all chat messages into the database.
I built this application to be scalable. So, my implementation of the websocket and webserver can be scaled up and distributed across several nodes.
If you want to look at a more lower level details, check out my objected-oriented design of the application.
This project wouldn't be possible without these valuable information resources.