SockJS server implementation for aiohttp.
Project description
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
Install virtualenv:
$ wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py $ python3.4 ./virtualenv.py --no-site-packages sockjs
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
websocket hybi-10
iframe-eventsource (EventSource used from an iframe via postMessage)
iframe-htmlfile (HtmlFile used from an iframe via postMessage.)
Not supported transports
websocket hixie-76
Requirements
Python 3.4
gunicorn 19.2.0
Examples
You can find several examples in the aiosockjs repository at github.
License
aiosockjs is offered under the Apache 2 license.
CHANGES
0.4 (02/03/2016)
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 (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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sockjs-0.4.zip
.
File metadata
- Download URL: sockjs-0.4.zip
- Upload date:
- Size: 50.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47fb0d6316cf6f3447ede76e63ce166f6ef2dcb3f4ba9ecc5e4befd7b54b248d |
|
MD5 | e5e3db0e8f78a7ff77522d015229b642 |
|
BLAKE2b-256 | a3fd158f212f1e7078c80dfbb3ed9c042cee109d3caee403970a7582e260c0a7 |
Provenance
File details
Details for the file sockjs-0.4-py3-none-any.whl
.
File metadata
- Download URL: sockjs-0.4-py3-none-any.whl
- Upload date:
- Size: 22.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a253434d6761f0c106a6784d0a685e4b9cb81df2456559d84c84b04007564f68 |
|
MD5 | f87a53925263a4cf5e3124492b59497d |
|
BLAKE2b-256 | 7464267519a2d9f8a25d595a45872706f112cda98a74d4db09d81d74d0288c4a |