{"id":24569424,"url":"https://github.com/flaviogrossi/sockjs-cyclone","last_synced_at":"2025-04-22T18:37:32.065Z","repository":{"id":3513396,"uuid":"4571140","full_name":"flaviogrossi/sockjs-cyclone","owner":"flaviogrossi","description":"SockJS server support for the Cyclone web server","archived":false,"fork":false,"pushed_at":"2014-08-13T07:20:13.000Z","size":409,"stargazers_count":26,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-01-12T12:30:20.086Z","etag":null,"topics":["cyclone","python","sockjs","sockjs-server","twisted","websocket"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flaviogrossi.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-06T10:14:36.000Z","updated_at":"2022-09-14T10:10:08.000Z","dependencies_parsed_at":"2022-08-20T08:50:47.064Z","dependency_job_id":null,"html_url":"https://github.com/flaviogrossi/sockjs-cyclone","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviogrossi%2Fsockjs-cyclone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviogrossi%2Fsockjs-cyclone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviogrossi%2Fsockjs-cyclone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaviogrossi%2Fsockjs-cyclone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flaviogrossi","download_url":"https://codeload.github.com/flaviogrossi/sockjs-cyclone/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235301395,"owners_count":18967941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cyclone","python","sockjs","sockjs-server","twisted","websocket"],"created_at":"2025-01-23T15:23:11.386Z","updated_at":"2025-01-23T15:23:13.098Z","avatar_url":"https://github.com/flaviogrossi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. contents:: Table of contents\n\n\nSockJS-cyclone\n==============\n\n.. image:: https://badge.fury.io/py/sockjs-cyclone.png\n    :target: https://pypi.python.org/pypi/sockjs-cyclone\n\n.. image:: https://secure.travis-ci.org/flaviogrossi/sockjs-cyclone.png?branch=master\n   :target: http://travis-ci.org/#!/flaviogrossi/sockjs-cyclone\n\n.. image:: https://pypip.in/d/sockjs-cyclone/badge.png\n   :target: https://crate.io/packages/sockjs-cyclone/\n\n.. image:: http://img.shields.io/badge/license-MIT-blue.svg\n   :target: http://opensource.org/licenses/MIT\n\nSockJS-cyclone is a pure Python server implementation for the\n`SockJS client library \u003chttps://github.com/sockjs/sockjs-client\u003e`_\nrunning on the `Cyclone \u003chttp://cyclone.io\u003e`_ web server.\n\nSockJS-cyclone is released under the `MIT license\n\u003chttps://github.com/flaviogrossi/sockjs-cyclone/tree/master/LICENSE\u003e`_.\n\nWhat is SockJS?\n---------------\n\n`SockJS \u003chttp://sockjs.org\u003e`_ is a browser JavaScript library that provides a\nWebSocket-like object.  SockJS gives you a coherent, cross-browser, JavaScript\nAPI which creates a low latency, full duplex, cross-domain communication\nchannel between the browser and the web server, which consistently works across\nold browsers, misconfigured or old proxies and firewalls, etc. by automatically\nusing other transports as a fallback mechanism.\n\nSockJS main features:\n\n- simple APIs, as close to the WebSocket API as possible;\n- scaling and load balancing techniques;\n- very fast connection establishment;\n- pure JavaScript library on the client-side, no flash needed;\n- very extensive code testing available for both the server and client sides.\n\nSockJS-cyclone fully supports the SockJS protocol version 0.3.3.\n\nWhat is Cyclone?\n----------------\n\n`Cyclone \u003chttp://cyclone.io\u003e`_ is a very fast and scalable web server framework\nthat implements the Tornado API as a Twisted protocol.\n\nHow does it look like?\n----------------------\n\nA live demo deployed on Heroku can be found `here \u003chttp://sockjs-cyclone-demo.herokuapp.com\u003e`_.\n\nHere is a small example for an echo server:\n\n.. code-block:: python\n\n    from twisted.internet import reactor\n    import cyclone\n    import sockjs.cyclone\n\n    class EchoConnection(sockjs.cyclone.SockJSConnection):\n        def messageReceived(self, message):\n            self.sendMessage(message)\n\n    if __name__ == \"__main__\":\n        EchoRouter = sockjs.cyclone.SockJSRouter(EchoConnection, '/echo')\n        app = cyclone.web.Application(EchoRouter.urls)\n        reactor.listenTCP(8888, app)\n        reactor.run()\n\nand an excerpt for the client:\n\n.. code-block:: javascript\n\n    var sock = new SockJS('http://mydomain.com/echo');\n    sock.onopen = function() {\n        console.log('open');\n    };\n    sock.onmessage = function(e) {\n        console.log('message', e.data);\n    };\n    sock.onclose = function() {\n        console.log('close');\n    };\n    sock.send('hello!');\n\nComplete examples `can be found here \u003chttps://github.com/flaviogrossi/sockjs-cyclone/tree/master/examples\u003e`_.\n\nMultiplexing\n------------\n\nSockJS-Cyclone supports multiplexing (multiple distinct channels over a single\nshared connection):\n\n.. code-block:: python\n\n    from twisted.internet import reactor\n    import cyclone\n    from sockjs.cyclone.conn import SockJSConnection, MultiplexConnection\n    from sockjs.cyclone.router import SockJSRouter\n\n    class AnnConnection(SockJSConnection):\n        def messageReceived(self, message):\n            self.sendMessage('Ann received ' + message)\n\n    class BobConnection(SockJSConnection):\n        def messageReceived(self, message):\n            self.sendMessage('Bob received ' + message)\n\n    class CarlConnection(SockJSConnection):\n        def messageReceived(self, message):\n            self.sendMessage('Carl received ' + message)\n\n    if __name__ == \"__main__\":\n        multiplexConnection = MultiplexConnection.create(ann=AnnConnection,\n                                                         bob=BobConnection,\n                                                         carl=CarlConnection)\n\n        echoRouter = SockJSRouter(multiplexConnection, '/echo')\n\n        app = cyclone.web.Application(echoRouter.urls)\n        reactor.listenTCP(8888, app)\n        reactor.run()\n\nSee the `websocket-multiplex \u003chttps://github.com/sockjs/websocket-multiplex\u003e`_\nlibrary for the client support, and the `complete example \n\u003chttps://github.com/flaviogrossi/sockjs-cyclone/tree/master/examples/multiplex\u003e`_.\n\n\nInstallation\n============\n\nInstall from pypi with:\n\n::\n\n    pip install sockjs-cyclone\n\nor from the latest sources with:\n\n::\n\n    git clone https://github.com/flaviogrossi/sockjs-cyclone.git\n    cd sockjs-cyclone\n    python setup.py install\n\n\nSockJS-cyclone API\n==================\n\nThe main interaction with SockJS-cyclone happens via the two classes\n``SockJSRouter`` and ``SockJSConnection``.\n\nSockJSConnection\n----------------\n\nThe ``SockJSConnection`` class represent a connection with a client and\ncontains the logic of your application. Its main methods are:\n\n- ``connectionMade(request)``: called when the connection with the client is\n  established;\n- ``messageReceived(message)``: called when a new message is received from the\n  client;\n- ``sendMessage(message)``: call when you want to send a new message to the\n  client;\n- ``close()``: close the connection;\n- ``connectionLost()``: called when the connection with the client is lost or\n  explicitly closed.\n\nSockJSRouter\n------------\n\nThe ``SockJSRouter`` class routes the requests to the various connections\naccording to the url prefix. Its main methods are:\n\n- ``__init__(connection, prefix, user_settings)``: bounds the given connection\n  to the given url prefix;\n- ``urls``: read only property to be used to initialize the cyclone application\n  with all the needed sockjs urls.\n\n\nDeployment\n==========\n\nSockJS servers are usually deployed in production behind reverse proxies and/or\nload balancers. The most used options are currently `Nginx \u003chttp://nginx.org\u003e`_\nand `HAProxy \u003chttp://haproxy.1wt.eu\u003e`_.\n\nFor Heroku deployment, see the `quickstart instructions here \u003chttps://github.com/flaviogrossi/sockjs-cyclone_heroku_quickstart\u003e`_.\n\nNginx\n-----\n\nTwo major options are needed to fully support proxying requests to a\nSockJS-Cyclone server: setting the HTTP protocol version to 1.1 and `passing\nupgrade headers to the server \u003chttp://nginx.org/en/docs/http/websocket.html\u003e`_.\nThe relevant portion of the required configuration is:\n\n::\n\n    server {\n        listen       80;\n        server_name  localhost;\n\n        location / {\n            proxy_pass          http://\u003csockjs_server\u003e:\u003cport\u003e;\n            proxy_http_version  1.1;\n            proxy_set_header    Upgrade $http_upgrade;\n            proxy_set_header    Connection \"upgrade\";\n            proxy_set_header    Host $http_host;\n            proxy_set_header    X-Real-IP $remote_addr;\n        }\n\n    }\n\nFor websocket support, nginx version 1.3.13 or above is needed.\n\nA working ``nginx.conf`` example can be found `in the examples directory \u003chttps://github.com/flaviogrossi/sockjs-cyclone/tree/master/examples/deployment\u003e`_.\n\nHAProxy\n-------\n\nA complete example for HAProxy deployment and load balancing can be found on\n``SockJS-Node`` `Readme \u003chttps://github.com/sockjs/sockjs-node#deployment-and-load-balancing\u003e`_.\n\n\nCredits\n=======\n\nThanks to:\n\n- Serge S. Koval for the tornado implementation;\n- VoiSmart s.r.l for sponsoring the project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaviogrossi%2Fsockjs-cyclone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflaviogrossi%2Fsockjs-cyclone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaviogrossi%2Fsockjs-cyclone/lists"}