Simple but powerful HTML5 Server-Sent Events (SSE) server for any kind of updates coming from the backend to the client This app is the integration of the Flask-SSE into a simple generic flask app. Refer to flask-sse docs for more info about the applicable settings.
Debian dependencies are in DEPENDENCIES file. You can install them automatically by:
make dependencies
To set up the development environment, run:
make develop
env/bin/python manage.py runserver
You can access your push server via http://localhost:8080/stream
As you need a non-blocking server, it's recommended to use gunicorn + gevent or just gevent wsgi server:
gunicorn -k gevent wsgi:app
from flask.ext.sse import send_event
send_event('myevent', {"message": "Hello!"}, channel='mychannel')
On the client side you just need a javascipt handler function which will be called when a new message is pushed from the server.
var source = new EventSource('/stream?channel=mychannel');
source.addEventListener('myevent', function (event) {
alert(event.data);
};
Server-Sent Events are supported by recent Firefox, Chrome and Safari browsers. Internet Explorer does not yet support Server-Sent Events, but is expected to support them in Version 10.
There are two recommended Polyfills to support older browsers
Mobile browsers have limited support, so test carefully if it works for your target set of browsers.
For testing purpose, there special test view: http://localhost:8080/test. It will make a browser alert on every myevent
event sent to test
channel.
If you have questions, bug reports, suggestions, etc. please create an issue on the GitHub project page.
This software is licensed under the MIT license
See License
© 2014 Paylogic International.