Last active
December 27, 2015 21:49
-
-
Save colegleason/7394672 to your computer and use it in GitHub Desktop.
simple websocket msgpack server
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
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