Skip to main content

SockJS server implementation for aiohttp.

Project description

https://secure.travis-ci.org/aio-libs/sockjs.png

aiosockjs is a SockJS server based on aiohttp PEP 3156 asyncio module.

aiosockjs 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>

Installation

  1. Install virtualenv:

    $ wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py
    $ python3.4 ./virtualenv.py --no-site-packages sockjs
  1. Clone aiosockjs from github and then install:

    $ git clone https://github.com/aio-libs/sockjs.git
    $ cd sockjs
    $ ../sockjs/bin/python setup.py develop

To run chat example use following command:

$ ./sockjs/bin/python ./aiosockjs/examples/chat.py

Supported transports

Not supported transports

Requirements

Examples

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

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

License

aiosockjs is offered under the Apache 2 license.

CHANGES

0.3 (08/07/2015)

  • Fixed calls of SessionManager.aquire() - was removed the unnecessary second argument.

  • Fixed the incorrect argument in one call of cors_headers().

  • Fixed many errors. The code is not perfect, but at least it was working as it should.

0.2 (07/07/2015)

  • Fixed packaging

0.1.0 (06/21/2015)

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sockjs-0.3.tar.gz (30.9 kB view details)

Uploaded Source

File details

Details for the file sockjs-0.3.tar.gz.

File metadata

  • Download URL: sockjs-0.3.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sockjs-0.3.tar.gz
Algorithm Hash digest
SHA256 bb40be3c95ace3ea610935a9bd38bea4c3fd5246cb5a4e2ef6ae57b3854f1ff9
MD5 d2c2202a0a79e393a5221ba4a86c0f06
BLAKE2b-256 63a0f18ed6495e3d3e38f8dd2b76cddd820fce5f47f53ffb81173997f30d00ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page