lua-resty-websocket icon indicating copy to clipboard operation
lua-resty-websocket copied to clipboard

How to delivery the websocket across request?

Open ruiyinchen opened this issue 9 years ago • 5 comments

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.

ruiyinchen avatar Aug 07 '14 08:08 ruiyinchen

Any one can write a chatting room example use the lua-resty-websocket for me . thx,very

ruiyinchen avatar Aug 07 '14 08:08 ruiyinchen

@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 avatar Aug 07 '14 17:08 agentzh

@agentzh ,thank very much.

ruiyinchen avatar Aug 08 '14 01:08 ruiyinchen

WebSockets with OpenResty by Aapo Talvensaari: https://medium.com/p/1778601c9e05

warmchang avatar Mar 16 '16 13:03 warmchang

@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

bungle avatar Mar 16 '16 16:03 bungle