On line (8) in the following, we have another message handler—this time using a custom event named led. Also notice on line (9) that this event handler has a data parameter, whereas the connect and disconnect handlers in the preceding section had no parameters. The data parameter contains data sent from the client, and we see, on line (10), the level child property of data. All data form clients are strings, so here we validate the data and cast it to an integer on the following line. There is no equivalent built-in argument validating and parsing utility with Flask-SocketIO, so we must perform validation checks manually, as shown starting on line (11):
@socketio.on('led') # (8)
def handle_state(data): # (9)
"""Handle 'led' messages to control the LED."""
global state
logger.info("Update LED from client {}: {} "
.format(request...