Recall & Review
beginner
What is a WebSocket in Flask?
A WebSocket in Flask is a way to open a two-way communication channel between the client and server. It allows sending and receiving messages instantly without reloading the page.
Click to reveal answer
beginner
Which Flask extension is commonly used for WebSocket support?
Flask-SocketIO is the extension that adds WebSocket support to Flask applications. It helps handle events like connect, disconnect, and message easily.
Click to reveal answer
intermediate
What does the @socketio.on('event_name') decorator do?
It tells Flask-SocketIO to listen for a specific event from the client named 'event_name'. When that event happens, the decorated function runs to handle it.
Click to reveal answer
intermediate
How do you send a message back to the client in Flask-SocketIO?
Use the emit() function inside an event handler. For example, emit('response_event', {'data': 'Hello'}) sends a message named 'response_event' with data to the client.
Click to reveal answer
beginner
What is the purpose of the 'connect' and 'disconnect' events in WebSocket handling?
The 'connect' event runs when a client opens a WebSocket connection. The 'disconnect' event runs when the client closes it. They help manage user sessions and resources.
Click to reveal answer
Which Flask extension is used to handle WebSocket events?
✗ Incorrect
Flask-SocketIO is designed to handle WebSocket events and real-time communication.
What decorator do you use to listen for a WebSocket event named 'chat_message'?
✗ Incorrect
The @socketio.on('event_name') decorator listens for WebSocket events with that name.
How do you send a message back to the client in Flask-SocketIO?
✗ Incorrect
The emit() function sends a named event with data back to the client.
What event runs when a client closes the WebSocket connection?
✗ Incorrect
The 'disconnect' event triggers when the client closes the connection.
Which of these is NOT a WebSocket event in Flask-SocketIO?
✗ Incorrect
'submit' is not a standard WebSocket event; 'connect', 'disconnect', and 'message' are.
Explain how Flask-SocketIO handles WebSocket events from client connection to message sending.
Think about the lifecycle of a WebSocket connection and how events are handled.
You got /5 concepts.
Describe the role of the @socketio.on decorator and the emit function in WebSocket communication.
Focus on how Flask-SocketIO listens and responds to events.
You got /3 concepts.