[uWSGI] How to get and store a websocket session?

timothy lee timlee246 at yahoo.com
Tue Apr 21 02:42:03 CEST 2015

Hello people,
I can do ws = environ['wsgi.websocket'] when I use gevent's wsgi server, but not when I use uwsgi. So how do I get and store a websocket session in uwsgi? 

from gevent import monkey; monkey.patch_all()
from gevent.pywsgi import WSGIServer
import uwsgi

class WebSocketApp(object):
    def __init__(self):
        self.my_dict = {}
        self.id_count = 0

    def __call__(self, environ, start_response):
            uwsgi.websocket_handshake(environ['HTTP_SEC_WEBSOCKET_KEY'], environ.get('HTTP_ORIGIN', ''))

            #works when using gevent's WSGI server but not when using uwsgi
            ws = environ['wsgi.websocket']

            self.my_dict[self.id_count] = ws
            self.id_count += 1
            while True:
                    msg = uwsgi.websocket_recv()
                except IOError, e:
                    return ""

    def send_msg(self, id, msg):

application = WebSocketApp()
Any Help would be much appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.unbit.it/pipermail/uwsgi/attachments/20150421/f7aba2c6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: temp.py
Type: text/x-python-script
Size: 869 bytes
Desc: not available
URL: <http://lists.unbit.it/pipermail/uwsgi/attachments/20150421/f7aba2c6/attachment.bin>

More information about the uWSGI mailing list