This project shows how to use Socket.IO for real-time communication between a frontend and a backend.
The frontend is made with React TypeScript and lets you add and remove widgets that subscribe to different topics. The widgets show the messages from the backend for each topic.
The frontend uses a SocketClient class to manage the Socket.IO connection and the subscribed topics. It also reconnects and resubscribes when needed.
The frontend saves messages in sessionStorage and removes old topics when it runs out of space.
The backend is made with Python, Flask, and Flask-SocketIO. It has an API for subscribing and unsubscribing to topics with socket.io events. The backend sends a random message for each topic every second to the subscribers.
The backend also has a debugging page that shows the subscribed topics for each session ID.
- Go to the
./frontend
directory. - Run
npm start
for debug mode ornpm run build && serve -s build
for release mode. - The frontend will be at localhost:3000.
Note: The frontend will be in strict mode when running npm start
and this may cause extra widget remounts and subscription events.
- Go to the
./backend
directory. - Run
./main.py
. - The backend debugging page will be at localhost:5001.