章大哥: 你好~ 我想在nginx启动的时候,同时也启动我自己的写的tcp客户端模块,也就是nginx启动的时候,我的tcp客户端自动连接到我的另一个tcp服务器上面,之后tcp服务器有数据到客户端的时候,客户端把收到的数据给nginx处理,这我需要怎么做呢,请指教。 --
Hello! 2014-10-15 2:27 GMT-07:00 xiatian1071: > 我想在nginx启动的时候,同时也启动我自己的写的tcp客户端模块,也就是nginx启动的时候,我的tcp客户端自动连接到我的另一个tcp服务器上面,之后tcp服务器有数据到客户端的时候,客户端把收到的数据给nginx处理,这我需要怎么做呢,请指教。 > 可以使用 init_worker_by_lua [1] + ngx.timer.at() [2] + ngx.socket.tcp() [3] 来实现这样的需求。 话说 lua-resty-upstream-healthcheck 库 [4] 的实现也使用的是类似的模式,可以作为参考。 Regards, -agentzh [1] https://github.com/openresty/lua-nginx-module#init_worker_by_lua [2] https://github.com/openresty/lua-nginx-module#ngxtimerat [3] https://github.com/openresty/lua-nginx-module#ngxsockettcp [4] https://github.com/openresty/lua-resty-upstream-healthcheck