Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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