Skip to content

aio-libs/sockjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a341ba8 · Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Sep 17, 2017
Jun 13, 2024
Dec 4, 2020
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024
Jun 13, 2024

Repository files navigation

SockJS server based on Asyncio (PEP 3156)

https://travis-ci.com/aio-libs/sockjs.svg?branch=master

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()
    app.router.add_route('GET', '/', index)
    sockjs.add_endpoint(app, prefix='/sockjs', handler=chatSession)
    web.run_app(app)

Client side code:

<script src="https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js"></script>
<script>
  var sock = new SockJS('http://localhost:8080/sockjs');

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

  sock.onmessage = function(e) {
    console.log('message', e.data);
    sock.close();
  };

  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.