{ "info": { "author": "Sergei Pikhovkin", "author_email": "s@pikhovkin.ru", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: Financial and Insurance Industry", "Intended Audience :: Healthcare Industry", "Intended Audience :: Manufacturing", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# A simple WebSocket server\n\n[![CircleCI](https://img.shields.io/circleci/project/github/pikhovkin/simple-websocket-server.svg)](https://circleci.com/gh/pikhovkin/simple-websocket-server)\n[![PyPI](https://img.shields.io/pypi/v/simple-websocket-server.svg)](https://pypi.org/project/simple-websocket-server/)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/simple-websocket-server.svg)\n[![PyPI - License](https://img.shields.io/pypi/l/simple-websocket-server.svg)](./LICENSE)\n\nBased on [simple-websocket-server](https://github.com/dpallot/simple-websocket-server).\n\n- RFC 6455 (All latest browsers)\n- TLS/SSL out of the box\n- Passes Autobahns Websocket Testsuite\n- Support for Python 2 and 3\n\n#### Installation\n\n pip install simple-websocket-server\n\n#### Echo Server Example\n\n`````python\nfrom simple_websocket_server import WebSocketServer, WebSocket\n\n\nclass SimpleEcho(WebSocket):\n def handle(self):\n # echo message back to client\n self.send_message(self.data)\n\n def connected(self):\n print(self.address, 'connected')\n\n def handle_close(self):\n print(self.address, 'closed')\n\n\nserver = WebSocketServer('', 8000, SimpleEcho)\nserver.serve_forever()\n`````\n\nOpen *tests/websocket.html* and connect to the server.\n\n#### Chat Server Example\n\n`````python\nfrom simple_websocket_server import WebSocketServer, WebSocket\n\n\nclass SimpleChat(WebSocket):\n def handle(self):\n for client in clients:\n if client != self:\n client.send_message(self.address[0] + u' - ' + self.data)\n\n def connected(self):\n print(self.address, 'connected')\n for client in clients:\n client.send_message(self.address[0] + u' - connected')\n clients.append(self)\n\n def handle_close(self):\n clients.remove(self)\n print(self.address, 'closed')\n for client in clients:\n client.send_message(self.address[0] + u' - disconnected')\n\n\nclients = []\n\nserver = WebSocketServer('', 8000, SimpleChat)\nserver.serve_forever()\n`````\nOpen multiple *tests/websocket.html* and connect to the server.\n\n#### Want to get up and running faster?\n\nThere is an example which provides a simple echo and chat server\n\nEcho Server\n\n python tests/example_server.py --example echo\n\nChat Server (open up multiple *tests/websocket.html* files)\n\n python tests/example_server.py --example chat\n\n#### TLS/SSL Example\n\n1) Generate a certificate with key\n\n openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout key.pem\n\n2) Run the secure TSL/SSL server (in this case the cert.pem file is in the same directory)\n\n python tests/example_server.py --example chat --ssl 1\n\n3) Offer the certificate to the browser by serving *tests/websocket.html* through https.\nThe HTTPS server will look for cert.pem in the local directory.\nEnsure the *tests/websocket.html* is also in the same directory to where the server is run.\n\n python tests/simple_https_server.py\n\n4) Open a web browser to: *https://localhost:443/tests/websocket.html*\n\n5) Change *ws://localhost:8000/* to *wss://localhost:8000* and click connect.\n\nNote: if you are having problems connecting, ensure that the certificate is added in your browser against the exception *https://localhost:8000* or whatever host:port pair you want to connect to.\n\n#### For the Programmers\n\nconnected: called when handshake is complete\n - self.address: TCP address port tuple of the endpoint\n\nhandle_close: called when the endpoint is closed or there is an error\n - self.address: TCP address port tuple of the endpoint\n\nhandle: gets called when there is an incoming message from the client endpoint\n - self.address: TCP address port tuple of the endpoint\n - self.opcode: the WebSocket frame type (STREAM, TEXT, BINARY)\n - self.data: bytearray (BINARY frame) or unicode string payload (TEXT frame) \n - self.request: HTTP details from the WebSocket handshake (refer to BaseHTTPRequestHandler)\n\nsend_message: send some text or binary data to the client endpoint\n - sending data as a unicode object will send a TEXT frame\n - sending data as a bytearray object will send a BINARY frame\n\nclose: send close frame to endpoint\n\n### Licensing\n\nMIT\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/pikhovkin/simple-websocket-server", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "simple-websocket-server", "package_url": "https://pypi.org/project/simple-websocket-server/", "platform": "", "project_url": "https://pypi.org/project/simple-websocket-server/", "project_urls": { "Homepage": "https://github.com/pikhovkin/simple-websocket-server" }, "release_url": "https://pypi.org/project/simple-websocket-server/0.4.0/", "requires_dist": null, "requires_python": "", "summary": "A simple WebSocket server", "version": "0.4.0" }, "last_serial": 4756032, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "885be0b1731c8f8be916731a9fb4d9a0", "sha256": "40ea3455b4246b94d26e4c182ebf921cf05a447f7696bf35e1cf4ce9e13ac988" }, "downloads": -1, "filename": "simple-websocket-server-0.1.1.tar.gz", "has_sig": false, "md5_digest": "885be0b1731c8f8be916731a9fb4d9a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6039, "upload_time": "2018-10-09T14:35:07", "url": "https://files.pythonhosted.org/packages/de/a0/594508e14a941ada34c23be82bb3fc571f466af7fba0f5c34976496c2b0a/simple-websocket-server-0.1.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "db218b648f95df6a5db53c8b77e2a25b", "sha256": "b8451541a024a6d5594d24aa8c5abdf12d5c8da7c2efe5c0faa7c71aacf3c7e6" }, "downloads": -1, "filename": "simple-websocket-server-0.3.0.tar.gz", "has_sig": false, "md5_digest": "db218b648f95df6a5db53c8b77e2a25b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8375, "upload_time": "2018-10-10T19:12:21", "url": "https://files.pythonhosted.org/packages/87/a9/7b7a35523a424cd32b074f2b7453030674280c208133cb7789b297ebf963/simple-websocket-server-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "65b740256ce0fafbdd40d4eb24f52697", "sha256": "6f98eb6f778a4beb0f7d95bea2c87aa283723fd457e75deb8392b76639a49a42" }, "downloads": -1, "filename": "simple-websocket-server-0.3.1.tar.gz", "has_sig": false, "md5_digest": "65b740256ce0fafbdd40d4eb24f52697", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8371, "upload_time": "2018-10-28T20:26:20", "url": "https://files.pythonhosted.org/packages/19/8c/5c2fff4f11ae4470fdfa951ad51ace47d38ef4d216d46915c7b3c926ef3e/simple-websocket-server-0.3.1.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "40b72171a5671c1942609b7f2da1817e", "sha256": "bbc4ab2c0614278ec87f2160a67e366e13957aeb4a847c6f67bae2fe3d1252e3" }, "downloads": -1, "filename": "simple-websocket-server-0.4.0.tar.gz", "has_sig": false, "md5_digest": "40b72171a5671c1942609b7f2da1817e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9674, "upload_time": "2019-01-29T18:00:18", "url": "https://files.pythonhosted.org/packages/96/df/fc1428d8ef95fcd0626afe8d6c74fda036d40197cd5d31d09315de14f0d9/simple-websocket-server-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "40b72171a5671c1942609b7f2da1817e", "sha256": "bbc4ab2c0614278ec87f2160a67e366e13957aeb4a847c6f67bae2fe3d1252e3" }, "downloads": -1, "filename": "simple-websocket-server-0.4.0.tar.gz", "has_sig": false, "md5_digest": "40b72171a5671c1942609b7f2da1817e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9674, "upload_time": "2019-01-29T18:00:18", "url": "https://files.pythonhosted.org/packages/96/df/fc1428d8ef95fcd0626afe8d6c74fda036d40197cd5d31d09315de14f0d9/simple-websocket-server-0.4.0.tar.gz" } ] }