I have found a bug that randomly appeared one day and still happens even with very simple code and a fresh new copy of gevent-websocket-0.9.5. When I call receive() on a WebSocket. It waits until a message is received and when one is (for example, I sent the word "foo bar" over the socket using JavaScript) it returns "None" and closes the socket. I am using Mac OS X 10.11.6, python 2.7. Here is the code I'm using: from bottle import Bottle, route, run, request, abort from geventwebsocket import WebSocketError from geventwebsocket.handler import WebSocketHandler from gevent.pywsgi import WSGIServer app = Bottle() @app.route('/') def index(): return 'Websocket test.' @app.route('/socket') def socket(): sock = request.environ.get('wsgi.websocket') if not sock: print 'Socket request aborted.' abort(400, 'Expected WS request.') try: while True: msg = sock.receive() print 'msg: '+str(msg) except WebSocketError as e: print e abort(400, 'WebSocketError (socket closed?') server = WSGIServer(('0.0.0.0', 8080), app, handler_class=WebSocketHandler) server.serve_forever()
I believe the problem is in websocket.py, in the function read_frame, where it throws a protocolerror at "if header.flags".