Python 烧瓶室
找到此样板文件,并想知道在向房间发送消息之前,是否确实需要加入房间Python 烧瓶室,python,socket.io,flask-socketio,Python,Socket.io,Flask Socketio,找到此样板文件,并想知道在向房间发送消息之前,是否确实需要加入房间 from flask import session from flask_socketio import emit, join_room, leave_room from .. import socketio @socketio.on('joined', namespace='/chat') def joined(message): """Sent by clients when they enter a room.
from flask import session
from flask_socketio import emit, join_room, leave_room
from .. import socketio
@socketio.on('joined', namespace='/chat')
def joined(message):
"""Sent by clients when they enter a room.
A status message is broadcast to all people in the room."""
room = session.get('room')
join_room(room)
emit('status', {'msg': session.get('name') + ' has entered the room.'}, room=room)
@socketio.on('text', namespace='/chat')
def text(message):
"""Sent by a client when the user entered a new message.
The message is sent to all people in the room."""
room = session.get('room')
emit('message', {'msg': session.get('name') + ':' + message['msg']}, room=room)
@socketio.on('left', namespace='/chat')
def left(message):
"""Sent by clients when they leave a room.
A status message is broadcast to all people in the room."""
room = session.get('room')
leave_room(room)
emit('status', {'msg': session.get('name') + ' has left the room.'}, room=room)
我不能将会议室存储在会话中并向会议室发送消息吗
@socketio.on('text', namespace='/chat')
def text(message):
"""Sent by a client when the user entered a new message.
The message is sent to all people in the room."""
room = session.get('room')
emit('message', {'msg': session.get('name') + ':' + message['msg']}, room=room)
是的,您可以发射到房间而不加入房间。你觉得这样做有什么问题吗?@Miguel我没试过谢谢你让我这么做know@Miguel如果我们可以在不加入的情况下向房间发射,那么使用加入房间()和离开房间()的另外两个事件会有什么好处?@Nahua加入/离开房间和发射是完全独立的操作,它们根本不相关,所以我不确定我是否理解你的要求。是的,你可以不加入房间就向房间发射。你觉得这样做有什么问题吗?@Miguel我没试过谢谢你让我这么做know@Miguel如果我们可以在不加入的情况下向房间发射,那么使用加入房间()和离开房间()的另外两个事件会有什么好处?@Nahua加入/离开房间和发射是完全独立的操作,它们根本不相关,所以我不确定我是否理解你的要求。