Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Flask-socketIO realtime example
from gevent import monkey
from flask import Flask, render_template
from flask.ext.socketio import SocketIO, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
def index():
return render_template('index.html')
def channel_a(message):
Receives a message, on `channel-a`, and emits to the same channel.
print "[x] Received\t: ", message
server_message = "Hi Client, I am the Server."
emit("channel-a", server_message)
print "[x] Sent\t: ", server_message
def say_hello_world():
Another way of emitting messages, when event based communication is
not possible
hello_message = "Hello World!"
socketio.emit("channel-a", hello_message)
print "[x] Sent\t: ", hello_message
if __name__ == '__main__':
app.debug = True, port=3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.