{ "info": { "author": "Dave Pallot", "author_email": "d.e.pallot@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "## A Simple Websocket Server written in Python\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\nYou can install SimpleWebSocketServer by running the following command...\n\n`sudo pip install git+https://github.com/dpallot/simple-websocket-server.git`\n\nOr by downloading the repository and running `sudo python setup.py install`. \nInstallation via pip is suggested.\n\n#### Echo Server Example\n`````python\nfrom SimpleWebSocketServer import SimpleWebSocketServer, WebSocket\n\nclass SimpleEcho(WebSocket):\n\n def handleMessage(self):\n # echo message back to client\n self.sendMessage(self.data)\n\n def handleConnected(self):\n print(self.address, 'connected')\n\n def handleClose(self):\n print(self.address, 'closed')\n\nserver = SimpleWebSocketServer('', 8000, SimpleEcho)\nserver.serveforever()\n`````\n\nOpen *websocket.html* and connect to the server.\n\n#### Chat Server Example\n`````python\nfrom SimpleWebSocketServer import SimpleWebSocketServer, WebSocket\n\nclients = []\nclass SimpleChat(WebSocket):\n\n def handleMessage(self):\n for client in clients:\n if client != self:\n client.sendMessage(self.address[0] + u' - ' + self.data)\n\n def handleConnected(self):\n print(self.address, 'connected')\n for client in clients:\n client.sendMessage(self.address[0] + u' - connected')\n clients.append(self)\n\n def handleClose(self):\n clients.remove(self)\n print(self.address, 'closed')\n for client in clients:\n client.sendMessage(self.address[0] + u' - disconnected')\n\nserver = SimpleWebSocketServer('', 8000, SimpleChat)\nserver.serveforever()\n`````\nOpen multiple *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 SimpleExampleServer.py --example echo\n\nChat Server (open up multiple *websocket.html* files)\n\n python SimpleExampleServer.py --example chat\n\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 SimpleExampleServer.py --example chat --ssl 1 --cert ./cert.pem\n\n3) Offer the certificate to the browser by serving *websocket.html* through https.\nThe HTTPS server will look for cert.pem in the local directory.\nEnsure the *websocket.html* is also in the same directory to where the server is run.\n\n sudo python SimpleHTTPSServer.py\n\n4) Open a web browser to: *https://localhost:443/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\nhandleConnected: called when handshake is complete\n - self.address: TCP address port tuple of the endpoint\n\nhandleClose: called when the endpoint is closed or there is an error\n - self.address: TCP address port tuple of the endpoint\n\nhandleMessage: 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\nsendMessage: 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\nsendClose: send close frame to endpoint\n\n\n---------------------\nThe MIT License (MIT)", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dpallot/simple-websocket-server/", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "SimpleWebSocketServer", "package_url": "https://pypi.org/project/SimpleWebSocketServer/", "platform": "", "project_url": "https://pypi.org/project/SimpleWebSocketServer/", "project_urls": { "Homepage": "https://github.com/dpallot/simple-websocket-server/" }, "release_url": "https://pypi.org/project/SimpleWebSocketServer/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "A Simple Websocket Server written in Python", "version": "0.1.1" }, "last_serial": 4789689, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "a2957da18e8813b340bddc4d11963ccc", "sha256": "d01ecd996d4e3b91e710c6ffaabe7b04661213d6c30e5c626395704de9cf0d5e" }, "downloads": -1, "filename": "SimpleWebsocketServer-0.1.1.tar.gz", "has_sig": false, "md5_digest": "a2957da18e8813b340bddc4d11963ccc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8003, "upload_time": "2019-02-07T05:45:23", "url": "https://files.pythonhosted.org/packages/41/9f/c410cceb0c8f55936e302aa128192a96c30cadc21769a5398f37e49b0ac2/SimpleWebsocketServer-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a2957da18e8813b340bddc4d11963ccc", "sha256": "d01ecd996d4e3b91e710c6ffaabe7b04661213d6c30e5c626395704de9cf0d5e" }, "downloads": -1, "filename": "SimpleWebsocketServer-0.1.1.tar.gz", "has_sig": false, "md5_digest": "a2957da18e8813b340bddc4d11963ccc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8003, "upload_time": "2019-02-07T05:45:23", "url": "https://files.pythonhosted.org/packages/41/9f/c410cceb0c8f55936e302aa128192a96c30cadc21769a5398f37e49b0ac2/SimpleWebsocketServer-0.1.1.tar.gz" } ] }