Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delivery the websocket across request? #8

Open
ruiyinchen opened this issue Aug 7, 2014 · 5 comments
Open

How to delivery the websocket across request? #8

ruiyinchen opened this issue Aug 7, 2014 · 5 comments

Comments

@ruiyinchen
Copy link

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
Copy link
Author

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

@agentzh
Copy link
Member

agentzh commented Aug 7, 2014

@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

@ruiyinchen
Copy link
Author

@agentzh ,thank very much.

@warmchang
Copy link

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

@bungle
Copy link
Member

bungle commented Mar 16, 2016

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants