Skip to main content
https://secure.travis-ci.org/ashleysommer/sanic-sockjs.svg

sanic_sockjs is a SockJS integration for Sanic. SockJS interface is implemented as a Sanic 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 Sanic web server is required:

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

Example of sockjs route:

def main(global_settings, **settings):
    app = Sanic(__main__)
    @app.get('/')
    def index(request):
        ...


    sanic_sockjs.add_endpoint(app, prefix='/sockjs', handler=chatSession)
    app.run("127.0.0.1", 8080)

Client side code:

<script src="//cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.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 sanic_sockjs repository at github.

https://github.com/ashleysommer/sanic-sockjs/tree/master/examples

License

sockjs is offered under the Apache 2 license.

CHANGES

0.1.0 (2020-04-08)

  • Initial release

  • Ported from aiohttp/SockJS

  • Works on all Sanic 19.3.1-to-19.12.2

Download files

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

Source Distribution

sanic-sockjs-0.1.0.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sanic_sockjs-0.1.0-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file sanic-sockjs-0.1.0.tar.gz.

File metadata

  • Download URL: sanic-sockjs-0.1.0.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.9

File hashes

Hashes for sanic-sockjs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a54134b1a9c3a198cbca6c624c54b53361cf48760fd9d6831ebf2481ba08619a
MD5 b010c9a18e84f62ea0010cc616967c00
BLAKE2b-256 6c5cad67cd74d50fff00cc4a57998b64b9bed0b95aaf61bacb39209a634a5a8d

See more details on using hashes here.

File details

Details for the file sanic_sockjs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sanic_sockjs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.9

File hashes

Hashes for sanic_sockjs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69e5c485de148f7a4a6530ecd5d7f01849779ec2c679d791ae36c37a4266562c
MD5 65afe40fa6c211a05c039561e1c3f38d
BLAKE2b-256 00ba7b14159f492f39af070b3682ae328f2379f9427269d9bc49b55684eb766e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

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