Il giorno 20/lug/2011, alle ore 16.52, Szymon Kosok ha scritto: > 2011/7/20 Roberto De Ioris <[email protected]>: >> >> Il giorno 20/lug/2011, alle ore 16.24, Szymon Kosok ha scritto: >> >>> Hi, >>> >>> I've asked this question on StackOverflow but I think it's better ask >>> here, so I copy&paste question. >>> >>> We are trying to integrate Socket.io with our website. All messages >>> are sent with uWSGI workers (Django). My problem is, that every >>> message does all connection magic. It looks now like that: >>> >>> Request -> HTTP Handshake with Socket.io -> Websocket connection -> >>> Data send -> Connection close >>> >>> And repeat for every message that need to be send to socket.io. It's >>> far from ideal. Sometimes there are 3-4 messages queued / request. Is >>> there way to share socket connection within requests with uWSGI? I >>> don't need sharing between workers, just only within all requests >>> processed by particular worker. Or maybe there are other solutions for >>> that problem? >>> >>> Best regards. >>> >> >> Hi, can you post the code you use to connect to the socket.io server ? > > Sure. :) > > I'm using websocket-client > http://pypi.python.org/pypi/websocket-client/0.4 and based on that > module my class: http://dpaste.com/572402/ (because socket.io needs > some funky handshake via http). > _
Looks like you can make a connection at the startup of your app and reuse it in each requests, but you will need to send a 'keepalive/ping' packet to leave it open. I have not tried it (i will try tomorrow and eventually i will send you an example) but you can create the connection in a @post_fork hook and leave it open with a @timer http://projects.unbit.it/uwsgi/wiki/Decorators (do not be afraid if you got nothing, it is an abstraction of other systems: http://projects.unbit.it/uwsgi/wiki/SignalFramework ) -- Roberto De Ioris http://unbit.it _______________________________________________ uWSGI mailing list [email protected] http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
