Skip to content

paylogic/pushserver

Repository files navigation

pushserver

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.

image

image

External dependencies

Debian dependencies are in DEPENDENCIES file. You can install them automatically by:

make dependencies

Development Environment

To set up the development environment, run:

make develop

Running the development instance

env/bin/python manage.py runserver

You can access your push server via http://localhost:8080/stream

Production deployment

As you need a non-blocking server, it's recommended to use gunicorn + gevent or just gevent wsgi server:

gunicorn -k gevent wsgi:app

Sending events to a push server from your app

from flask.ext.sse import send_event

send_event('myevent', {"message": "Hello!"}, channel='mychannel')

Client side

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.

Test view

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.

Contact

If you have questions, bug reports, suggestions, etc. please create an issue on the GitHub project page.

License

This software is licensed under the MIT license

See License

© 2014 Paylogic International.

About

Simple but powerful HTML5 Server-Sent Events (SSE) server for any kind of updates coming from the backend to the client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages