Skip to content

prashantm1535/flask_chat_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Chat Application with Flask and SocketIO.

Real-Time Chat Application with Flask and SocketIO

This project is a real-time chat application built with Flask and Flask-SocketIO, enabling seamless real-time communication between users. The app automatically assigns random usernames and avatars to connected users and allowing them to join the chat, send messages and update their usernames. All user activities such as joining, messaging, and leaving are broadcasted to all participants in real-time.

Features:

  • Random Usernames & Avatars: Each user is assigned a random username and avatar upon connection.
  • Real-Time Communication: Messages are broadcasted to all connected users instantly using WebSockets.
  • Username Updates: Users can change their usernames, and changes are reflected in real-time for all users.
  • User Join/Leave Notifications: The application broadcasts notifications when users join or leave the chat.
  • WebSocket Events:
    • connect: Assigns a random username and avatar to the user.
    • disconnect: Notifies others when a user leaves the chat.
    • send_message: Handles sending and broadcasting messages from users.
    • update_username: Allows users to update their username, notifying all participants of the change.

Technologies Used:

  • Backend: Flask, Flask-SocketIO (WebSockets for real-time communication).

  • Frontend: HTML, CSS, JavaScript (SocketIO client library for real-time updates).


How to Run:

To run the Flask-SocketIO app locally, follow these steps:

Prerequisites:

  • Python (3.x) installed on your machine.
  • pip (Python package manager) installed.

Steps:

  1. Clone the repository (or download the project files):

    mkdir chat_app
    cd chat_app
    git clone https://github.com/prashantm1535/chat_app.git
  2. Create a virtual environment (optional but recommended): This step isolates your project dependencies.

  • On Windows:

    python -m venv .venv
    .venv\Scripts\activate
  • On macOS/Linux:

    python3 -m venv .venv
    source .venv/bin/activate
  1. Install dependencies: Install the required Python packages using the requirements.txt file.

    pip install -r requirements.txt
  2. Run the Flask application: Run the app using the socketio.run function provided in the app.py file.

    python app.py
  3. Access the app in your browser: Open your web browser and navigate to:

    http://localhost:5000
    

Optional:

  • If you're developing the app and want the server to auto-reload upon file changes, ensure that debug=True is set in the following line:
    socketio.run(app, debug=True)

By following these steps, the application should be fully operational on your local machine!


Some resource links used in this projects :

Avatar URL :

avatar url