Created
January 28, 2014 19:15
-
-
Save tpdn/8674214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import request, Bottle, abort | |
app = Bottle() | |
@app.route('/websocket') | |
def handle_websocket(): | |
wsock = request.environ.get('wsgi.websocket') | |
if not wsock: | |
abort(400, 'Expected WebSocket request.') | |
while True: | |
try: | |
message = wsock.receive() | |
wsock.send("Your message was: %r" % message) | |
except WebSocketError: | |
break | |
from gevent.pywsgi import WSGIServer | |
from geventwebsocket import WebSocketError | |
from geventwebsocket.handler import WebSocketHandler | |
server = WSGIServer(("0.0.0.0", 8080), app, | |
handler_class=WebSocketHandler) | |
server.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment