how to having tcp socket on body_filter_by_lua_file ?

53 views
Skip to first unread message

Hadi Abbasi

unread,
Apr 11, 2018, 9:29:36 AM4/11/18
to openresty-en
https://github.com/openresty/lua-nginx-module#ngxsockettcphey guys
I want to create a tcp socket connection inside a lua file...
but my lua file is used on body_filter_by_lua_file tag !
I can see that tcp socket is just supported on  rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*
https://github.com/openresty/lua-nginx-module#ngxsockettcp

so I want to get a perfect suggestion about calling a method from that lua file to creating a tcp socket connection! 
I have to use it on 
body_filter_by_lua_file  but I don't know how to connect to tcp socket from my body_filter_by_lua_file  lua!
please help me,
thanks a lot...
Best...

tokers

unread,
Apr 11, 2018, 9:59:17 PM4/11/18
to openresty-en
Hello!

As the document mentinos, you cannot use Cosocket in body_filter_by_lua*. What about spawn a timer in body_filter_by_lua* and use Cosocket inside the timer?

Robert Paprocki

unread,
Apr 11, 2018, 10:01:10 PM4/11/18
to openre...@googlegroups.com
Be careful because body filters can run multiple times per request. Caution and good design is needed here. 

Sent from my phone 

On Apr 11, 2018, at 18:59, tokers <zcha...@gmail.com> wrote:

Hello!

As the document mentinos, you cannot use Cosocket in body_filter_by_lua*. What about spawn a timer in body_filter_by_lua* and use Cosocket inside the timer?

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted
Message has been deleted

Hadi Abbasi

unread,
Apr 17, 2018, 1:52:01 AM4/17/18
to openresty-en
thanks a lot...
I used ngx.timer.at inside body_filter_by_lua_file script and then I defined a function which created  tcp socket to sending data to the server and now it has no error like that!
so I see that timer can solve calling some classes in unavailable tags...
good luck...
Reply all
Reply to author
Forward
0 new messages