Bird
0
0

What does the decorator @socketio.on('message') do in a Flask app using WebSocket?

easy📝 Conceptual Q11 of 15
Flask - WebSocket and Real-Time
What does the decorator @socketio.on('message') do in a Flask app using WebSocket?
AIt closes the WebSocket connection.
BIt sends a WebSocket message to all connected clients.
CIt listens for incoming WebSocket messages with the event name 'message'.
DIt initializes the Flask app.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the decorator role

    The @socketio.on('message') decorator registers a function to handle incoming WebSocket events named 'message'.
  2. Step 2: Differentiate from other actions

    Sending messages or closing connections are done by other functions, not by this decorator.
  3. Final Answer:

    It listens for incoming WebSocket messages with the event name 'message'. -> Option C
  4. Quick Check:

    Decorator for event handling = C [OK]
Quick Trick: Remember: @socketio.on listens, send() sends [OK]
Common Mistakes:
MISTAKES
  • Confusing event handler with sending messages
  • Thinking it closes connections
  • Assuming it initializes the app

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes