This project demonstrates a simple WebSocket chat app using FastAPI and Python.
- 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
8000is busy
Install the dependencies:
pip install -r requirements.txtIn one terminal, start the server:
python .\server.pyThe 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.
In another terminal, start the client:
python .\client.pyType a message and press Enter. The server will receive it and send a JSON response back.
server.py- FastAPI WebSocket serverclient.py- WebSocket clientrequirements.txt- Python dependencies