Created
June 8, 2024 12:30
-
-
Save Hunter87ff/b79ae41ab6eb3fd916096089cc3fe3de to your computer and use it in GitHub Desktop.
Basic socketio server and client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import socketio | |
| sio = socketio.Client(reconnection=True) | |
| @sio.event | |
| def connect(): | |
| print("Connected to the server") | |
| sio.send("Hello world!") | |
| @sio.event | |
| def message(data): | |
| print(f"Received message: {data}") | |
| @sio.event | |
| def disconnect(): | |
| print("Disconnected from server") | |
| sio.connect("http://localhost:5000") | |
| sio.wait() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| from flask_socketio import SocketIO, send | |
| app = Flask(__name__) | |
| socketio = SocketIO(app) | |
| @socketio.on('message') | |
| def handle_message(msg): | |
| print('Message received: ' + msg) | |
| send(msg) | |
| socketio.run(app, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment