https://github.com/aio-libs/sockjs
SockJS Server
https://github.com/aio-libs/sockjs
aiohttp asyncio sockjs websockets
Last synced: 6 months ago
JSON representation
SockJS Server
- Host: GitHub
- URL: https://github.com/aio-libs/sockjs
- Owner: aio-libs
- License: apache-2.0
- Created: 2015-04-06T03:14:54.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-12-25T16:58:06.000Z (about 1 year ago)
- Last Synced: 2025-06-09T07:08:36.721Z (7 months ago)
- Topics: aiohttp, asyncio, sockjs, websockets
- Language: Python
- Size: 535 KB
- Stars: 118
- Watchers: 13
- Forks: 40
- Open Issues: 8
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
SockJS server based on Asyncio (PEP 3156)
=========================================
.. image:: https://travis-ci.com/aio-libs/sockjs.svg?branch=master
:target: https://travis-ci.com/aio-libs/sockjs
`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::
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');
};
Supported transports
--------------------
* websocket `hybi-10
`_
* `xhr-streaming
`_
* `xhr-polling
`_
* `iframe-xhr-polling
`_
* iframe-eventsource (`EventSource
`_ used from an `iframe via
postMessage
`_)
* iframe-htmlfile (`HtmlFile
`_
used from an *iframe via postMessage*.
* `jsonp-polling `_
Requirements
------------
- Python 3.10.0
- gunicorn 19.2.0
- aiohttp https://github.com/aio-libs/aiohttp
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.