Skip to content

pramitsaha123/python-fastapi-websocket-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI WebSocket Demo

This project demonstrates a simple WebSocket chat app using FastAPI and Python.

Features

  • A FastAPI server with a WebSocket endpoint at /ws
  • A simple Python client that connects to the server
  • Automatic fallback to another local port if port 8000 is busy

Requirements

Install the dependencies:

pip install -r requirements.txt

Run the Server

In one terminal, start the server:

python .\server.py

The server will start on http://127.0.0.1:8000 unless that port is unavailable, in which case it will use the next available port.

Run the Client

In another terminal, start the client:

python .\client.py

Type a message and press Enter. The server will receive it and send a JSON response back.

Files

  • server.py - FastAPI WebSocket server
  • client.py - WebSocket client
  • requirements.txt - Python dependencies

About

A beginner-friendly Python project demonstrating real-time communication with WebSockets using FastAPI. Learn WebSocket connections, async programming, client-server messaging, and JSON responses through a simple, well-documented example. Perfect for understanding the fundamentals of real-time applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages