Skip to content

drod1107/PySocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PySocket

Minimal WebSocket chat demo.

Requirements

  • Python 3.12+
  • Postgres running locally with database chatapp
  • Install dependencies:
    pip install -r requirements.txt
  • websockets library (pip install -r requirements.txt)

Usage

  1. Install dependencies:

    pip install -r requirements.txt
  2. Run the server:

    python chat_server.py

    The static file server listens on http://localhost:8000, the auth and conversation API on http://localhost:8001, The HTTP server listens on http://localhost:8000 and the WebSocket server on ws://localhost:6789.

  3. Open http://localhost:8000/index.html in two browser windows or machines and start chatting.

Messages from one browser window will appear in the other in real time.

Authentication API

Create a user account:

curl -X POST http://localhost:8001/signup \
  -H 'Content-Type: application/json' \
  -d '{"email": "user@example.com", "password": "secret"}'

Log in with the created account:

curl -X POST http://localhost:8001/login \
  -H 'Content-Type: application/json' \
  -d '{"email": "user@example.com", "password": "secret"}'

The login response includes a JSON token field which can be used for authenticated requests.

Create a conversation between users:

curl -X POST http://localhost:8001/conversations \
  -H "Authorization: Bearer <TOKEN>" \
  -H 'Content-Type: application/json' \
  -d '{"members": ["user@example.com", "friend@example.com"]}'

Connect via WebSocket using the returned conversation id:

ws://localhost:6789?token=<TOKEN>&conv=<ID>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published