{ "info": { "author": "Ole Kristian Aune, Even Dalen, Audun Wigum Arbo", "author_email": "even.dalen@live.no", "bugtrack_url": null, "classifiers": [], "description": "simple\\_ws\n==========\n\nSimple websocket implementation in python\n\n|PyPI version| |Python version|\n\nInstall\n-------\n\n::\n\n $ pip install simple_ws\n\nUsage\n-----\n\nTo test the library, clone repo, open two command windows and cd into\nthe python-WS directory\n\n- Run ``python -m http.server 8000``\n- Run ``python ws_example.py`` in the other window\n- Open http://localhost:8000 in a browser\n\nExample\n~~~~~~~\n\n.. code:: python\n\n from simple_ws import WebSocket\n\n class WSHandler(WebSocket):\n def on_message(self, msg, target_client):\n for client in self.clients:\n if client.is_open():\n client.write_message(msg)\n\n def on_open(self, client):\n print(\"Client connected!\")\n\n def on_close(self, client):\n print(\"Client left...\")\n\n def on_ping(self, client):\n print(\"Recieved ping!\")\n\n def on_pong(self, client):\n print(\"Recieved pong!\")\n\n host = ''\n port = 8080\n\n ws = WSHandler(host, port)\n\nWebSocket parameters\n--------------------\n\n+------------+------------+------------+------------+\n| parameter | type | default | descriptio |\n| | | | n |\n+============+============+============+============+\n| ``host`` | String | | Host |\n| | | | domain |\n+------------+------------+------------+------------+\n| ``port`` | Integer | | Port |\n| | | | number for |\n| | | | websocket |\n+------------+------------+------------+------------+\n| ``ping`` | Boolean | True | Whether |\n| | | | server |\n| | | | should |\n| | | | ping |\n| | | | client in |\n| | | | a given |\n| | | | intervall, |\n| | | | will close |\n| | | | connection |\n| | | | if pong is |\n| | | | not |\n| | | | received |\n+------------+------------+------------+------------+\n| ``ping_int | Integer | 5 | How often |\n| ervall`` | | | should |\n| | | | server |\n| | | | ping |\n| | | | client in |\n| | | | seconds, |\n| | | | has no |\n| | | | effect if |\n| | | | ping is |\n| | | | set to |\n| | | | false |\n+------------+------------+------------+------------+\n| ``compress | Boolean | True | Whether |\n| ion`` | | | messages |\n| | | | should be |\n| | | | compressed |\n+------------+------------+------------+------------+\n| ``max_fram | Integer | 8192 | Max size |\n| e_size`` | | | for a |\n| | | | single |\n| | | | websocket |\n| | | | frame. If |\n| | | | payload |\n| | | | exceeds |\n| | | | limit, the |\n| | | | message |\n| | | | will be |\n| | | | split in |\n| | | | several |\n| | | | parts |\n+------------+------------+------------+------------+\n| ``buffer_s | Integer | 4096 | Max |\n| ize`` | | | network |\n| | | | buffer |\n| | | | size |\n+------------+------------+------------+------------+\n\nFunctions\n---------\n\nWebSocket\n~~~~~~~~~\n\non\\_open(self, client)\n^^^^^^^^^^^^^^^^^^^^^^\n\nCalled when the server opens a connection to a new client (client).\n\n.. code:: python\n\n def on_open(self, client):\n # Executes when opening a connection\n\non\\_close(self, client)\n^^^^^^^^^^^^^^^^^^^^^^^\n\nCalled when the server closes a connection to a client (client).\n\n.. code:: python\n\n def on_close(self, client):\n # Executes when closing a connection\n\non\\_message(self, msg, client)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nCalled when the server has received a message (msg) from a client\n(client). The message can be in either binary or text format.\n\n.. code:: python\n\n def on_message(self, msg, client):\n # Executes when server recieves a messages from client\n\non\\_ping(self, client)\n^^^^^^^^^^^^^^^^^^^^^^\n\nCalled when the server sends a ping to a client (client).\n\n.. code:: python\n\n def on_ping(self, client):\n # Executes when ping is sent to a client\n\non\\_pong(self, client)\n^^^^^^^^^^^^^^^^^^^^^^\n\nCalled when the server receives a pong from a client (client).\n\n.. code:: python\n\n def on_pong(self, client):\n # Executes when pong is received from a client\n\nClient\n~~~~~~\n\nwrite\\_message(self, msg, binary=False)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nSends a message payload (msg) to the client. If binary=True, the message\ngets sent as binary data.\n\n.. code:: python\n\n # Text message\n client.write_message(\"Hello world\")\n\n # Binary message\n client.write_message(b\"0x00\", binary=True)\n\nis\\_open(self)\n^^^^^^^^^^^^^^\n\nReturns True if the connection has gone through handshake, and is\ncurrently open.\n\nclose(self, status, reason)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nSends a close frame to the client, and closes the connection after\neither a response, or after 1 second. Status and reason are not\ncurrently implemented. Will ultimately result in **WebSocket.on\\_close**\nbeing fired.\n\n.. code:: python\n\n client.close(1002, \"Pong not recieved\")\n\nTODO\n----\n\n1. Write more tests\n2. Add support for payload in ping and pong frames\n3. Error handling\n4. Clean up classes\n5. Implement close status and reason\n6. Implement all compression configurations\n7. Add more configurability/remove hardcoded constants\n8. Implement connection limit\n\nExternal sources\n----------------\n\n- https://tools.ietf.org/html/rfc6455\n- https://tools.ietf.org/html/rfc7692\n- https://developer.mozilla.org/en-US/docs/Web/API/WebSockets\\_API/Writing\\_WebSocket\\_servers\n- https://www.igvita.com/2013/11/27/configuring-and-optimizing-websocket-compression/\n- https://github.com/tornadoweb/tornado\n- https://docs.python.org/3/library/asyncio.html\n\nLicense\n-------\n\n`MIT License `__\n\nAuthors\n-------\n\n`Even Dalen `__, `Audun Wigum\nArbo `__ and `Ole Kristian\nAune `__\n\n.. |PyPI version| image:: https://badge.fury.io/py/simple_ws.svg\n :target: https://badge.fury.io/py/simple_ws\n.. |Python version| image:: https://img.shields.io/badge/python-3.6.1-blue.svg\n :target: https://www.python.org/downloads/release/python-361/\n", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/WSnettverksprog/simple_ws/archive/0.3.0.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/WSnettverksprog/simple_ws", "keywords": "websocket", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "simple_ws", "package_url": "https://pypi.org/project/simple_ws/", "platform": "", "project_url": "https://pypi.org/project/simple_ws/", "project_urls": { "Download": "https://github.com/WSnettverksprog/simple_ws/archive/0.3.0.tar.gz", "Homepage": "https://github.com/WSnettverksprog/simple_ws" }, "release_url": "https://pypi.org/project/simple_ws/0.3.1/", "requires_dist": null, "requires_python": "", "summary": "Simple websocket implementation in python using asyncio", "version": "0.3.1" }, "last_serial": 2866616, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "84873eb161b5693c000dd5cef4464b06", "sha256": "2628ed1758925045581c041aeabb025090a404599833fe6959eaab77d649f9bc" }, "downloads": -1, "filename": "simple_ws-0.1.zip", "has_sig": false, "md5_digest": "84873eb161b5693c000dd5cef4464b06", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6869, "upload_time": "2017-05-02T19:30:58", "url": "https://files.pythonhosted.org/packages/df/7f/45ac4bf1887084ac6b88020d9f9ba8138d30cc23048af6e93b024e9c0bed/simple_ws-0.1.zip" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "8c7e5f7c30df38855ff646ebef4600b6", "sha256": "cf335e8811f5474889a2b56d2417d74c14e7d59b3bff00490f028c78963608af" }, "downloads": -1, "filename": "simple_ws-0.2.2.zip", "has_sig": false, "md5_digest": "8c7e5f7c30df38855ff646ebef4600b6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8427, "upload_time": "2017-05-03T14:42:06", "url": "https://files.pythonhosted.org/packages/19/14/e43aa55f7f660e0eeeb93518c40e3b458d3af228bb1ba63b2c4d8c4bf47d/simple_ws-0.2.2.zip" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "bef486fb92077234a1dfae0fa83ae6a5", "sha256": "9ddd1afe70c4c0859f60c805241fc6993ee72fa7efb3d1d3cc52168b64a1b213" }, "downloads": -1, "filename": "simple_ws-0.3.1.tar.gz", "has_sig": false, "md5_digest": "bef486fb92077234a1dfae0fa83ae6a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7431, "upload_time": "2017-05-10T09:44:42", "url": "https://files.pythonhosted.org/packages/d9/f2/4aa9c27788ab90e24a44576f66afe9f8168efbaa6d28fc3a3ffc2074fc0b/simple_ws-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bef486fb92077234a1dfae0fa83ae6a5", "sha256": "9ddd1afe70c4c0859f60c805241fc6993ee72fa7efb3d1d3cc52168b64a1b213" }, "downloads": -1, "filename": "simple_ws-0.3.1.tar.gz", "has_sig": false, "md5_digest": "bef486fb92077234a1dfae0fa83ae6a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7431, "upload_time": "2017-05-10T09:44:42", "url": "https://files.pythonhosted.org/packages/d9/f2/4aa9c27788ab90e24a44576f66afe9f8168efbaa6d28fc3a3ffc2074fc0b/simple_ws-0.3.1.tar.gz" } ] }