lua-resty-websocket
lua-resty-websocket copied to clipboard
How to delivery the websocket across request?
I want to find all the current connect sock to the websocket server, and send response to them.(a chatting room.) I Save the socks to module table in every request. When I use the saved socks to send response,I found that the socks already closed.How Can I do , I Know the cosocket has the same lifetime as the request.How can I shared sock across request.
Any one can write a chatting room example use the lua-resty-websocket for me . thx,very
@ruiyinchen Instead of delivering sockets themselves across different requests, you should delivery data or message. You cannot operate on a cosocket object directly from the context of another request that did not create it.
BTW, such general discussions should go to the openresty-en mailing list. See http://openresty.org/#Community
@agentzh ,thank very much.
WebSockets with OpenResty by Aapo Talvensaari: https://medium.com/p/1778601c9e05
@ruiyinchen,
Here is chat-app that I wrote to demonstrate some of my components for OpenResty Con 2015: https://github.com/bungle/iresty
For web sockets, see: https://github.com/bungle/iresty/blob/master/site/bootstrap.lua#L37
And: https://github.com/bungle/iresty/blob/master/site/app/chat.lua
It uses Redis as a backend and pub/sub channel. You could do without Redis and use shared dict for example, but well, take a look.
But remember, it is just a demo.
It uses resty.websocket, as you can se here (this is an abstraction in my route framework to route websockets packets): https://github.com/bungle/iresty/blob/master/libs/resty/route/websocket/handler.lua