Skip to content

LocalChat is a locally hosted chatroom for everyone inside your Wifi. You are able to write messages via flask websocket to single local IPs or in the main chat.

Notifications You must be signed in to change notification settings

MEGADragon20/LocalChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LocalChat

LocalChat is a locally hosted chatroom for everyone connected to the same WiFi network. It provides a simple, clean interface for group conversations and private messaging between users using Flask, Flask-SocketIO, and PostgreSQL.

Features

  • Main Chat: Real-time group messaging for all connected users
  • Private Chats: Direct messaging between two users by IP address
  • Clean UI: Simple white-themed interface optimized for usability
  • Local Network Only: Works across any WiFi network without internet
  • Message History: All messages stored in PostgreSQL database
  • Real-time Updates: WebSocket-based instant messaging

Requirements

System Requirements

  • Python 3.8+
  • PostgreSQL 12+
  • Windows/Mac/Linux

Python Dependencies

  • Flask 2.3.0
  • Flask-SocketIO 5.3.0
  • Flask-SQLAlchemy 3.0.5
  • psycopg2-binary 2.9.6
  • python-dotenv 1.0.0

Installation

1. Clone the Repository

git clone https://github.com/yourusername/LocalChat.git
cd LocalChat

2. Create PostgreSQL Database

CREATE DATABASE localchat;

3. Set Up Python Environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

4. Install Dependencies

pip install -r requirements.txt

5. Configure Environment Variables

Create a .env file in the root directory:

DATABASE_URL=postgresql://postgres:your_password@localhost/localchat
SECRET_KEY=your-super-secret-key-change-this
FLASK_ENV=development

Replace your_password with your PostgreSQL password.

6. Run the Application

python app.py

The application will be available at http://localhost:5000 and accessible from other devices on the same network using your machine's local IP (e.g., http://192.168.1.100:5000).

Usage

Finding Your Local IP

  • Windows: Open Command Prompt and run ipconfig. Look for "IPv4 Address"
  • Mac/Linux: Open Terminal and run ifconfig or hostname -I

Accessing LocalChat

  1. On any device on the same WiFi, go to http://<your-local-ip>:5000
  2. Select Main Chat to join the group conversation, or
  3. Select Private Chat and enter the last octet of an IP address (e.g., for 192.168.1.42, enter 42)

Network Setup

LocalChat automatically detects the connecting user's IP address. Private chats use the last octet of the IP for identification, making it easy to find specific users on your network (e.g., 172.168.4.x).

Project Structure

LocalChat/
├── app.py                 # Main Flask application
├── requirements.txt       # Python dependencies
├── .env                   # Environment configuration
├── .gitignore            # Git ignore rules
├── static/
│   └── styles.css        # Clean white-themed CSS
├── templates/
│   ├── overview.html     # Landing page
│   ├── main_chat.html    # Group chat interface
│   └── private_chat.html # Private chat interface
└── README.md             # This file

Database Schema

Messages Table

CREATE TABLE messages (
    id SERIAL PRIMARY KEY,
    sender_ip VARCHAR(15) NOT NULL,
    recipient_ip VARCHAR(15),
    content TEXT NOT NULL,
    timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    room_type VARCHAR(10) DEFAULT 'main'
);

Users Table

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    ip_address VARCHAR(15) UNIQUE NOT NULL,
    last_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

WebSocket Namespaces

  • /main: Main chat namespace for group messaging
  • /private: Private chat namespace with room-based filtering

Security Considerations

⚠️ Important: This application is designed for local network use only.

  • Change the SECRET_KEY in .env before deployment
  • Only use on trusted networks
  • Consider adding authentication for production use
  • Messages are stored in plaintext; encrypt sensitive data if needed

Troubleshooting

Can't connect to PostgreSQL

  • Ensure PostgreSQL is running
  • Check your credentials in .env
  • Verify the database exists: CREATE DATABASE localchat;

WebSocket connection fails

  • Check firewall settings
  • Ensure port 5000 is not blocked
  • Try disabling browser extensions that might interfere

Messages not appearing

  • Check Flask console for errors
  • Verify database connection
  • Reload the page and try again

Future Enhancements

  • User authentication and profiles
  • Message encryption
  • File sharing
  • User status indicators
  • Message reactions and typing indicators
  • Docker containerization

License

MIT License - Feel free to use this project for personal or commercial purposes.

Support

For issues, questions, or suggestions, please open an issue on GitHub.

About

LocalChat is a locally hosted chatroom for everyone inside your Wifi. You are able to write messages via flask websocket to single local IPs or in the main chat.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published