This is a chatroom that I have coded up a while ago for one of the my projects.
- Web Browser: Google Chrome is recommended for the best experience.
- Python 3: Ensure Python 3 is installed to run the server script.
- Code Editor: Any code editor (e.g., VS Code, PyCharm) to manage the server script.
- Ngrok: A tool to expose your local server to the internet.
- REQUIRED_HUMAN_AGENTS: This setting allows you to specify the number of human participants the chatroom is expecting. Adjust this value in the configuration or relevant script (e.g.,
server_script.pyorchatViews.py) to match the desired number of users.
To make the chatroom accessible across devices, you'll need to install Ngrok.
-
Mac: Run the following command in your terminal:
brew install ngrok
-
Other Platforms (Windows, Linux, etc.): Download Ngrok from the official website: https://ngrok.com/download. Follow the instructions there to install it.
Follow these steps to set up and run the chatroom:
-
Open the Chatroom UI:
- Open the
chatRoom.htmlfile in Google Chrome (or another modern browser).
- Open the
-
Run the Server Script:
- Open your code editor and navigate to the directory containing
server_script.py. - In a terminal, run the following command to start the server (if you want to use ngrok):
or (if you want to run on the local machine and not use ngrok)
python3 server_script.py 0.0.0.0 8080
python3 server_script.py localhost 8080
- This will start the server on port
8080.
- Open your code editor and navigate to the directory containing
-
Expose the Server with Ngrok:
- In a separate terminal, run the following command:
ngrok http 8080
- Ngrok will generate a public URL, such as:
Forwarding https://abc123.ngrok-free.app -> http://localhost:8080 - Copy the public URL (e.g.,
abc123.ngrok-free.app).
- In a separate terminal, run the following command:
-
Connect to the Chatroom:
- In the
chatRoom.htmlinterface, locate the Server Address field. - Paste the copied Ngrok URL (e.g.,
abc123.ngrok-free.app) into the Server Address field. - Enter the username and connect to the server.
- In the
- The
chatViews.pyfile contains the Django views that handle the backend logic for the chatroom. Ensure this file is properly configured within your Django project to manage chatroom functionality, such as message handling and user connections.
Once connected, you can communicate with others across different devices using the chatroom interface. Ensure the server script and Ngrok are running continuously to maintain the connection. The REQUIRED_HUMAN_AGENTS setting ensures the chatroom waits for the specified number of participants before enabling full functionality.
- Server not running: Ensure the
python3 server_script.py 0.0.0.0 8080command is active and there are no errors in the terminal. - Ngrok URL not working: Verify that Ngrok is running and the correct URL is copied. Check for typos in the Server Address field.
- Browser issues: If the UI does not load correctly, try refreshing the page or using Google Chrome.
- Django views errors: Ensure
chatViews.pyis correctly integrated into your Django project and all dependencies are installed.
For additional help, refer to the Ngrok documentation: https://ngrok.com/docs or the Django documentation: https://docs.djangoproject.com.