Skip to main content

SockJS server implementation for aiohttp.

Project description

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

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.

CHANGES

0.9.1 (2018-12-04)

  • Minor code styling cleanups

0.9.0 (2018-10-11)

  • Support Python 3.7. The minimal available Python version is 3.5.3 (#240)

0.8.0 (2018-06-15)

  • Fix heartbeat (#214)

0.7.1 (2018-03-05)

  • Fix compatibility with aiohttp 3.0+ again.

0.7.0 (2018-02-25)

  • Fixed compatibility with aiohttp 3.0+ (#169)

0.6 (2017-04-13)

  • Fixed support for aiohttp 2.0+.

0.5 (2016-09-26)

  • Mark SockJSRoute.handler and SockJSRoute.websocket as coroutines. #25

  • Remove a check for “ORIGIN” header #12

  • Process FRAME_MESSAGE_BLOB message type #12

0.4 (2016-02-04)

  • Fixed lost event-loop argument in sockjs.transports.websocket.WebSocketTransport

  • Fixed lost event-loop argument in sockjs.transports.rawwebsocket.RawWebSocketTransport

  • Fixed RawRequestMessage. Add raw_header argument (aiohttp 0.21+)

  • Fixed many warnings

  • Fixed sockjs.route add_endpoint without name bug

0.3 (2015-08-07)

  • 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 (2015-07-07)

  • Fixed packaging

0.1.0 (2015-06-21)

  • 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.9.1.tar.gz (31.7 kB view details)

Uploaded Source

Built Distribution

sockjs-0.9.1-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sockjs-0.9.1.tar.gz
  • Upload date:
  • Size: 31.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for sockjs-0.9.1.tar.gz
Algorithm Hash digest
SHA256 5bd86cba705b73b7daaad2a081ca9b539d0d9f5eb163f1b1454644dfb8cb63e8
MD5 f42066f98b90f191a799e608ce2255e1
BLAKE2b-256 b445ef5bec2591228b3428131ed76ddde3125ae0ab161a0f03274fc897d49ea0

See more details on using hashes here.

Provenance

File details

Details for the file sockjs-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: sockjs-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for sockjs-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0391b069f38ca686030c4f322e0a6e38e3ee54cb6aca991fa8f4dcb0a694ab4e
MD5 3faa5c00f5a92600d27f7b61575f88ba
BLAKE2b-256 58f0c2c88d28efa863c142e15656d9eb09fcd2c000d05d7ab37f81c86549a89c

See more details on using hashes here.

Provenance

Supported by

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