This repository contains the source code for a simple chat application implemented in both Python and C++. It includes a WebSocket server written in each language and a single web-based client that can connect to either server.
/
├── python/
│ └── server.py # Python WebSocket server
├── cpp/
│ ├── chat_server.cpp # C++ WebSocket server
│ └── include/ # Include directory for external headers
│ └── nlohmann/ # JSON library for C++
└── client/
└── index.html # Web client for the chat application
- Python 3.x
websockets
library
- C++11 compiler (e.g., g++)
- Boost Libraries
- WebSocket++ library
- nlohmann/json library
- Install Python 3.x (if not installed): Python Installation Guide
- Install Dependencies:
pip install websockets
- Install C++ Build Tools: Ensure
g++
andCMake
are installed. - Install Boost Libraries:
sudo apt-get install libboost-all-dev
- Install WebSocket++:
git clone https://github.com/zaphoyd/websocketpp.git
- Install nlohmann/json:
sudo apt-get install nlohmann-json3-dev
To run the Python server, navigate to the python
directory and execute the following command:
python server.py
This will start the WebSocket server on localhost:8765
.
To build and run the C++ server, navigate to the cpp
directory and execute the following commands:
- Compile the Server:
g++ -std=c++11 chat_server.cpp -o chat_server -I ./websocketpp -I ./include -lboost_system -lpthread
- Run the Server:
./chat_server
This will compile and start the WebSocket server on localhost:8765
.
Open the client/index.html
file in any modern web browser to connect to the running WebSocket server. Ensure that either the Python or C++ server is running before opening the client.
- Enter a username in the provided input field.
- Type a message and click
Send
to broadcast it to all connected clients. - Received messages from other clients will be displayed in real time.
- The C++ server requires proper setup of WebSocket++ and Boost, including ensuring that paths in the compilation command are correct.
- Both servers listen on the same port (
8765
), so ensure that only one server is running at a time when using the client.