Only missing feature that will make this Lua module (and openresty) ready to make realtime web apps is WebSocket support.
I dunno exactly how to do it, but it would be just awesome if we could also have sthing like websocket_by_lua that will launch script on new websocket, then this script could (somehow) install handlers (functions) for WebSocket frame and close events.
You could also just use the Nginx Push Stream Module which supports EventSource, WebSocket, Long Polling, Forever Iframe, etc.
Thanks a lot for pointing me to this module! Now I need to study it carefully.
Looks like It requires nginx support for websockets, which is not planned to be implemented soon as far as I know.
But generally I like the Idea.
I think this would really open up openresty to some interesting use cases
Now that Nginx has a support for websockets, is there a possibility for running web sockets with this module?
Curious how this went?
Haven't got the time to work on this. Being busy with other stuffs like the new timer API in ngx_lua and other small features and fixes.
We would also be very interested in this feature. Since we would mainly use the websocket connection to continuously send data to the server the push stream module mentioned above does not help us.
Any progress on this?
@hendrik-schumacher No progress yet. But it's still somewhere near the top of my TODO list :)
@agentzh Did you have time to look into this meanwhile? Is there any way to make you push this to the top of your list?
@hendrik-schumacher Sorry, I've been busy with other things in the openresty project, mostly performance tuning and bug fixes.
To push this to the top of my list, you have to find someone to sponsor it so that I can consider working on it in my own time.
I've implemented the first prototype of the websocket support for ngx_lua.
You need to use the "websocket" git branch in ngx_lua's repository for now. Also, you need to use the lua-resty-websocket library:
Thanks Aapo Talvensaari for writing a nice blog post on the basic usage of this new feature:
Please try it out and send feedback to me :) Thanks!
The "websocket" git branch of ngx_lua has already been merged into "master". I've run the whole ngx_lua and lua-resty-websocket test suite on Amazon EC2 with various different testing modes:
Fixed a bug leading to segfault exposed by the test suite.
The new websocket support of ngx_lua will be included in the next formal release. For now, please use the "master" branch instead of "websocket".
I'm closing this issue. If there's any issue regarding the current websocket implementation, please file separate issues accordingly.
If you read the great article by Aapo Talvensaari and are banging your head because it just disconnects after you click connect, add a final slash to the Websocket's url.
Example: ws = new WebSocket('ws://127.0.0.1/s'); should be ws = new WebSocket('ws://127.0.0.1/s/');