SockJS Server
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
docs Polish README Oct 20, 2017
examples Fix #215: Update example to use async function Jun 15, 2018
sockjs Bump to 0.8.0 Jun 15, 2018
tests
.coveragerc cleanups and tests Apr 14, 2015
.gitignore Minor neats Mar 5, 2018
.pyup.yml Schedule pyup bot every week Sep 17, 2017
.travis.yml Update travis config to use aio-libs-bot user for deployment Jun 15, 2018
CHANGES.txt
LICENSE.txt Update LICENSE.txt Jan 3, 2016
MANIFEST.in fix packaging Jul 7, 2015
Makefile update deps Mar 16, 2017
README.rst Fix README checker May 8, 2018
requirements.txt Scheduled weekly dependency update for week 24 (#216) Jun 18, 2018
setup.cfg Add strict warnings mode Feb 25, 2018
setup.py Bump to 0.7.0 Feb 25, 2018
sockjs-testsrv.py Fix message.type attribute Mar 5, 2018

README.rst

SockJS server based on Asyncio (PEP 3156)

sockjs is a SockJS integration for aiohttp. SockJS interface is implemented as a aiohttp route. Its possible to create any number of different sockjs routes, ie /sockjs/* or /mycustom-sockjs/*. You can provide different session implementation and management for each sockjs route.

Simple aiohttp web server is required:

[server:main]
use = egg:gunicorn#main
host = 0.0.0.0
port = 8080
worker = aiohttp.worker.GunicornWebWorker

Example of sockjs route:

def main(global_settings, **settings):
    app = web.Application(loop=loop)
    app.router.add_route('GET', '/', index)
    sockjs.add_endpoint(app, prefix='/sockjs', handler=chatSession)

    handler = app.make_handler()
    srv = loop.run_until_complete(
        loop.create_server(handler, '127.0.0.1', 8080))
    print("Server started at http://127.0.0.1:8080")
    try:
        loop.run_forever()
     except KeyboardInterrupt:
        srv.close()
        loop.run_until_complete(handler.finish_connections())

Client side code:

<script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
<script>
    var sock = new SockJS('http://localhost:8080/sockjs');

    sock.onopen = function() {
      console.log('open');
    };

    sock.onmessage = function(obj) {
      console.log(obj);
    };

    sock.onclose = function() {
      console.log('close');
    };
</script>

Supported transports

Requirements

Examples

You can find several examples in the sockjs repository at github.

https://github.com/aio-libs/sockjs/tree/master/examples

License

sockjs is offered under the Apache 2 license.