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

Roberto De Ioris roberto at unbit.it
Tue Apr 21 06:24:17 CEST 2015


> I see. The thing is is that I have another greenlet running that is
> listening through a zeromq port. And depending on what messages I get from
> it, I need to send a message to a certain client, and the server can have
> many clients connected to it. So the only way I can think of to do this is
> to store the websocket session in a dictionary so I can look up which
> client to send a message to.  How can I accomplish this if I can't do it
> the way my example did? 
>


the rule is that a different context (thread, process, greenlet) cannot
access the request/response session of another one. This enforces
transparent support for multiple paradigms.

The common approach is telling the greenlet/process/thread (once the
websocket session is established) to wait for some event (redis is a easy
way to accomplish it, but i suppose you can create a zeromq channel too).

When the "external" greenlet has something to send it simply enqueue a
message back to the channel of the right request context.

With this technique you can support multiple greenlet in multiple
processes too.

-- 
Roberto De Ioris
http://unbit.com


More information about the uWSGI mailing list