This project demonstrates the implementation of WebSockets in a Django application, enabling real-time message exchange between users in the same chat room. Redis is used as the message broker, running on Docker.
- Python (3.8 or later)
- Django
- Channels library for WebSocket support
- Redis running on the default port (6379)
-
Clone the repository:
git clone git@github.com:aditya-8-88/DjangoWebSockets.git cd DjangoWebSockets
-
Create and activate a virtual environment:
python -m venv env source env/bin/activate # On Windows use `env\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Run database migrations:
python manage.py makemigrations python manage.py migrate
-
Install and run Redis:
sudo apt-get install redis-server sudo service redis-server start
Or use docker (optional):
docker pull redis:latest docker run -d --name redis-container -p 6379:6379 redis:latest
-
Start the development server:
python manage.py runserver
- Open two tabs in your browser.
- Navigate to the chat interface (e.g., http://127.0.0.1:8000/chat/).
- Enter the same room name in both tabs.
- Send a message from one tab, and observe it appearing in real time on the other tab.
- Ensure Docker is running and the Redis container is active before starting the server.
- For any issues with Redis connectivity, verify that port 6379 is not blocked and that Redis is accessible