Created
January 4, 2023 10:13
-
-
Save iTrooz/9a0b41f0ef2b6fe784c0c2d67d295246 to your computer and use it in GitHub Desktop.
Flask-SocketIO rooms hello world
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() | |
sio.connect('http://localhost:5000') | |
sio.emit('join', {"username": "iTrooz", "room":"myroom"}) | |
@sio.on('chat') | |
def on_message(data): | |
print('Received message: ', data) |
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 join_room, emit | |
from flask_socketio import SocketIO | |
app = Flask("testapp") | |
socketio = SocketIO(app) | |
@socketio.on('join') | |
def on_join(data): | |
print("socket msg") | |
username = data['username'] | |
room = data['room'] | |
join_room(room) | |
emit('chat', username + ' has entered the room.', room=room) | |
socketio.run(app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment