GEVENT-WEBSOCKET(1) gevent-websocket GEVENT-WEBSOCKET(1) NAME gevent-websocket - gevent-websocket Documentation gevent-websocket is a WebSocket library for the gevent networking library written written and maintained by Jeffrey Gelens It is licensed under the BSD license. from geventwebsocket import WebSocketServer, WebSocketApplication, Resource class EchoApplication(WebSocketApplication): def on_message(self, message): self.ws.send(message) WebSocketServer( ('', 8000), Resource({'/': EchoApplication}) ) It isn't necessary to use the build-in WebSocketServer to start using WebSockets. WebSockers can be added to existing applications very easy by making the non-standard wsgi.websocket variable available in the WSGI environment. An example using Flask follows: from geventwebsocket import WebSocketServer, WebSocketError from flask import Flask, request, render_template app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') @app.route('/api') def api(): ws = request.environ.get('wsgi.websocket') if not ws: abort(400, "Expected WebSocket request") while True: try: message = ws.receive() ws.send("Your message was: {}".format(message)) except WebSocketError: # Possibility to execute code when connection is closed break if __name__ == '__main__': server = WebSocketServer(("", 8000), app) server.serve_forever() Also the browser Javascript application can be very simple: o Framework for WebSocket servers and WebSocket subprotocols o Implementation of RFC6455 and Hybi-10+ o gevent based: high performance, asynchronous o standards conformance (100% passes the Autobahn Websocket Testsuite) DISTRIBUTE & PIP Installing gevent-websocket is simple with pip: $ pip install gevent-websocket GET THE CODE Requests is being developed on BitBucket. You can clone the repsistory: hg clone https://www.bitbucket.org/Jeffrey/gevent-websocket or download the tarball: curl -LO https://bitbucket.org/Jeffrey/gevent-websocket/TODO Once you have a copy, you can either embed it in your application, or installed it on your system with: $ python setup.py install MAIN CLASSES EXCEPTIONS o Index o Module Index o Search Page AUTHOR Jeffrey Gelens COPYRIGHT 2024, Jeffrey Gelens 0.10 April 6, 2024 GEVENT-WEBSOCKET(1)