Bird
0
0

What is wrong with this Flask-SocketIO server code snippet? ```python @socketio.on('connect') def on_connect(): socketio.emit('welcome', {'msg': 'Hi'}) return 'Connected' ```

medium📝 Debug Q7 of 15
Flask - WebSocket and Real-Time
What is wrong with this Flask-SocketIO server code snippet? ```python @socketio.on('connect') def on_connect(): socketio.emit('welcome', {'msg': 'Hi'}) return 'Connected' ```
AMissing argument in emit call
BReturning a value in connect handler is invalid
CDecorator should be @app.route
DFunction name must be 'connect_handler'
Step-by-Step Solution
Solution:
  1. Step 1: Understand connect event handler rules

    Connect handlers should not return values; return is ignored or causes error.
  2. Step 2: Check emit call and decorator

    Emit call is correct with event name and data; decorator @socketio.on('connect') is correct.
  3. Final Answer:

    Returning a value in connect handler is invalid -> Option B
  4. Quick Check:

    Connect handlers must not return values [OK]
Quick Trick: Do not return values from connect event handlers [OK]
Common Mistakes:
MISTAKES
  • Returning from connect handler
  • Using wrong decorators
  • Assuming function names are fixed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes