emit('my response', ) # Trigger a new event called "my response" # that can be caught by another callback later in the program.if __name__ == '__main__': socketio.run(app) Four events are allowed in the @socketio.on() decorator – ‘connect’, ‘disconnect’, ‘message’, and ‘json’.For example, allowing events like a continually updating message stream, a notification system, or a specific Twitter monitor / display.
Implementing event triggers or binding event callbacks are very simply implemented in Flask (after some initial setup) using:# Basic blask server to catch events from flask import Flask, render_template from socketio import Socket IO, emit app = Flask(__name__) app.config['SECRET_KEY'] = 'secret!
' socketio = Socket IO(app) @socketio.on('my event') # Decorator to catch an event called "my event": def test_message(message): # test_message() is the event callback function.
As a webmaster, you may find it a frustrating task to do it on time year after year.
Let us explore some of the ways to auto update the copyright year on a website.
Preparing your websites for the New Year or revising the content?
Feel like updating of copyright year is a monotonous and tedious task?
In this specific example, we want the server to be continually working in the background generating new information, while at the same time allowing new clients to connect, and pushing new information to connected clients.
For this purpose, we’ll be using the Python threading module to create a thread that generates random numbers regularly, and emits the newest value to all connected clients.
Flask is an extremely lightweight and simple framework for building web applications using Python.
Python Flask Micro Framework for developing web applications " data-medium-file="https://shanelynnwebsite-mid9n9g1q9y8tt.netdna-ssl.com/wp-content/uploads/2014/07/flask-300x117.png" data-large-file="https://shanelynnwebsite-mid9n9g1q9y8tt.netdna-ssl.com/wp-content/uploads/2014/07/flask-1024x400.png" class="aligncenter wp-image-248 size-medium" src="https://shanelynnwebsite-mid9n9g1q9y8tt.netdna-ssl.com/wp-content/uploads/2014/07/flask-300x117.png" alt="Flask logo" width="300" height="117" srcset="https://shanelynnwebsite-mid9n9g1q9y8tt.netdna-ssl.com/wp-content/uploads/2014/07/flask-300x117300w, https://shanelynnwebsite-mid9n9g1q9y8tt.netdna-ssl.com/wp-content/uploads/2014/07/flask-1024x4001024w" sizes="(max-width: 300px) 100vw, 300px" will start a server on your local machine with one page saying “Hello World!
An updated copyright not only shows that the site is maintained but also gets it rated high on SEO search lists.