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.3
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.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
File details
Details for the file sockjs-0.1.tar.gz
.
File metadata
- Download URL: sockjs-0.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52f0372295c20c01bcd8af05b4577ebf6f072a7fb77b0cd5a2fede642c020f10 |
|
MD5 | 54a37a74c2a64918829961704f69c576 |
|
BLAKE2b-256 | 8b7e6b7f06d69800f52f293871a4453724f0801fbf125c844a2c1f8914205057 |