Skip to content

Instantly share code, notes, and snippets.

@colegleason
Last active December 27, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save colegleason/7394672 to your computer and use it in GitHub Desktop.
Save colegleason/7394672 to your computer and use it in GitHub Desktop.
simple websocket msgpack server
import gevent.monkey
gevent.monkey.patch_all()
import msgpack
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
def websocket_app(environ, start_response):
print('Connected')
if environ["PATH_INFO"] == '/':
ws = environ["wsgi.websocket"]
run = [0]
def receive():
while 1:
msg_data = ws.receive()
msg = msgpack.loads(msg_data)
print(msg)
g = gevent.spawn(receive)
pywsgi.WSGIServer(("", 8080), websocket_app,
handler_class=WebSocketHandler).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment