{"id":23020227,"url":"https://github.com/brainrake/jsonrpcws","last_synced_at":"2025-04-02T18:40:48.011Z","repository":{"id":139111111,"uuid":"1328997","full_name":"brainrake/jsonrpcws","owner":"brainrake","description":"JSON-RPC over WebSockets","archived":false,"fork":false,"pushed_at":"2011-04-20T12:49:54.000Z","size":108,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T09:13:50.866Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brainrake.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-02-04T18:10:44.000Z","updated_at":"2013-11-05T08:11:08.000Z","dependencies_parsed_at":"2023-03-13T10:50:06.611Z","dependency_job_id":null,"html_url":"https://github.com/brainrake/jsonrpcws","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Fjsonrpcws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Fjsonrpcws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Fjsonrpcws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainrake%2Fjsonrpcws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainrake","download_url":"https://codeload.github.com/brainrake/jsonrpcws/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246871096,"owners_count":20847420,"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":[],"created_at":"2024-12-15T12:13:32.412Z","updated_at":"2025-04-02T18:40:47.985Z","avatar_url":"https://github.com/brainrake.png","language":"Python","readme":"\nJSON-RPC over WebSockets\n========================\n\n\nThis is an implementation of\n`JSON-RPC 1.0\n\u003chttp://json-rpc.org/wiki/specification\u003e`_\nover `WebSockets\n\u003chttp://dev.w3.org/html5/websockets/\u003e`_.\n\nThe server is implemented in Python, using the `Eventlet\n\u003chttp://eventlet.net/\u003e`_\nnetworking library.\n\nThe client is ECMAScript (JavaScript), and runs in the\nlatest browsers supporting WebSockets.\n\n\nProject Status\n--------------\n\nThe project is in **alpha** state.\nIt is functionally complete, but is yet to be tested extensively.\n\n\nUsage\n-----\n\nThe server needs the ``Eventlet`` python networking library.\nto install it on debian-based systems, do\n``sudo apt-get install python-eventlet``.\n\n\nServer\n~~~~~~\n\nTo create a service, subclass ``JsonRpcWsService`` and decorate it with \n``@eventlet.websocket.WebSocketWSGI``.\n\nAny methods defined in the inner class `local` can be called remotely.\nThey receive the service instance as the first argument.\n\nYou can override the event handlers ``oninit()`` and ``onclose()`` for\nadditional functionality.\n\nThe id of the current request is available through ``service._id`` .\nIf this value is not ``None``, the method has to return a\n``(result, error)`` tuple.\n\nThe Eventlet WebSocket object is available through ``service.ws`` .\n\nTo send messages, use ``notify(self, method, params)`` and \n``request(self, method, params, callback=None)``.\nThe callback gets two arguments: ``result`` and ``error``.\nTo explicitly send a response, use ``respond(self, id, result, error)``.\n\nYou can also ``close()`` the socket.\n\nExample: ::\n\n    @eventlet.websocket.WebSocketWSGI\n    class MyService(jsonrpcws.JsonRpcWsService):\n        class local: # the methods in this class can be called remotely\n            def hello(service, name):\n                print \"got hello from\", name\n                if self._id: # if this is a request, not a notification\n                    return ( [\"hi, \"+name], None) # return a (response, error) tuple\n        def oninit(self):\n            print self.ws.environ\n            self.nofify(\"hi\",[\"the server\"])\n\nTo run it, pass the class (not an instance) to ``eventlet.wsgi.server``.\nA new instance will be created for every incoming WebSocket connection. ::\n\n    eventlet.wsgi.server(eventlet.listen(('', 8888)), MyService)\n\n\nClient\n~~~~~~\n\nTo create a service, instantiate JsonRpcWsService. The client API is\nalmost identical to the server. Methods defined in the ``local``\nobject will be remotely callable. The service instance is available\nthrough ``this``.\n\n``notify``, ``request``, ``respond``, ``close``, ``oninit`` and\n``onclose`` are similarly available.\n\nThe WebSocket instance is available through ``this.ws`` .\n\n\nExample: ::\n\n    var service_def = {\n        local:{\n            hi: function(who){\n                alert(\"got hi from \"+who)\n            }\n        },\n        onopen: function(){\n            this.notify(\"hello\", [\"the client\"])\n        }\n    }\n    var service = new JsonRpcWsService(\"ws://localhost:8888/\",service_def)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainrake%2Fjsonrpcws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainrake%2Fjsonrpcws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainrake%2Fjsonrpcws/lists"}