Bird
0
0

In Flask-SocketIO, which method is used to listen for a custom WebSocket event named 'join'?

easy📝 Conceptual Q1 of 15
Flask - WebSocket and Real-Time
In Flask-SocketIO, which method is used to listen for a custom WebSocket event named 'join'?
A@socketio.on('join')
B@app.route('join')
C@socketio.emit('join')
D@socketio.handle('join')
Step-by-Step Solution
Solution:
  1. Step 1: Understand event listening in Flask-SocketIO

    Flask-SocketIO uses the decorator @socketio.on(event_name) to listen for events from clients.
  2. Step 2: Identify the correct decorator for 'join' event

    To listen for the 'join' event, you use @socketio.on('join'). Other options are incorrect because @app.route is for HTTP routes, @socketio.emit sends events, and @socketio.handle is not a valid decorator.
  3. Final Answer:

    @socketio.on('join') -> Option A
  4. Quick Check:

    Event listening decorator = @socketio.on('event') [OK]
Quick Trick: Use @socketio.on('event') to listen for WebSocket events [OK]
Common Mistakes:
MISTAKES
  • Using @app.route for WebSocket events
  • Confusing emit with on decorator
  • Using non-existent decorators like @socketio.handle

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes