Bird
0
0

What is wrong with this Flask-SocketIO broadcast code?

medium📝 Debug Q7 of 15
Flask - WebSocket and Real-Time
What is wrong with this Flask-SocketIO broadcast code?
@socketio.on('notify')
def notify_handler(msg):
    socketio.emit('notify_response', msg, broadcast=True, room='room1')
ACannot use broadcast=True and room parameter together
BEvent name 'notify_response' is invalid
Cbroadcast parameter must be False to use room
DFunction must call socketio.send instead of emit
Step-by-Step Solution
Solution:
  1. Step 1: Understand broadcast and room parameters

    broadcast=True sends to all clients; room targets specific clients. They cannot be used together.
  2. Step 2: Check other options

    Event name is valid; broadcast does not have to be False but cannot combine with room; send is not required.
  3. Final Answer:

    Cannot use broadcast=True and room parameter together -> Option A
  4. Quick Check:

    broadcast and room cannot be combined [OK]
Quick Trick: broadcast=True and room param cannot be used together [OK]
Common Mistakes:
MISTAKES
  • Using broadcast and room together
  • Assuming event name is invalid
  • Thinking send must replace emit

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes