Skip to content

Ameneh-Keshavarz/Live-Chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 

Repository files navigation

Live Chat Application

A real-time chat application with two different implementations: WebSocket and Long Polling.

Overview

This repository contains two approaches to building real-time chat applications:

  • WebSocket - Bidirectional persistent connection for instant messaging
  • Long Polling - HTTP-based polling mechanism for message updates

Both implementations demonstrate different techniques for achieving real-time communication.

Project Structure

Live-Chat/
├── WebSocket/        # WebSocket-based chat with authentication
│   ├── backend/      # Express.js + WebSocket server
│   ├── frontend/     # Vite + Vanilla JS client
│   └── README.md
└── LongPolling/      # Long polling-based chat
    ├── backend/      # Express.js server
    ├── frontend/     # Vanilla JS client
    └── README.md

WebSocket Implementation

A full-featured chat application with user authentication, message reactions, and persistent database.

Features:

  • User registration and login with JWT
  • Real-time messaging via WebSocket
  • Message reactions (like/dislike)
  • SQLite database with Knex
  • Secure HTTP-only cookies
  • Comprehensive error handling

Tech: Express.js, WebSocket (ws), SQLite3, Knex.js, JWT, Bcrypt

Quick Start:

cd WebSocket/backend
npm install
node migrations/init.js
node app.js

# In another terminal
cd WebSocket/frontend
npm install
npm run dev

Open http://localhost:5173

Long Polling Implementation

A lightweight chat application using HTTP long polling for message retrieval.

Features:

  • Simple user messaging
  • No authentication required
  • In-memory message storage
  • Minimal dependencies
  • Long polling mechanism with 25-second timeout

Tech: Express.js, Vanilla JavaScript

Quick Start:

cd LongPolling/backend
npm install
npm start

# Open LongPolling/frontend/index.html in browser

Comparison

Feature WebSocket Long Polling
Connection Type Persistent HTTP polling
Latency Instant 100ms polling
Scalability Requires connection management Simpler to scale
Complexity Higher Lower
Database SQLite In-memory
Authentication JWT + Bcrypt None
Reactions Yes No

Getting Started

Choose one implementation and follow the Quick Start guide above, or check individual README files in each directory for detailed documentation.

Tech Stack

Common:

  • Node.js
  • Express.js

WebSocket:

  • WebSocket (ws)
  • SQLite3
  • JWT
  • Bcrypt

Long Polling:

  • CORS

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published