如何通过 openresty lua 代理发送 tcp 请求

如题所述

普通连接代码如下:
-- check.lua

local portHandler = function(premature, ip_address, port)
local sock = ngx.socket.tcp()
sock:settimeout(300)
local ok, err = sock:connect(ip_address, port)

if ok then
-- 数据库处理或文件处理写入历史
local ok, err = ngx.timer.at(1, hHandler, ip_address, port);
if not ok then
ngx.log(ngx.ERR, "failed to create timer: ", err)
end
else
ngx.log(ngx.ERR, "port_handler_error: " .. ip_address, err)
end
sock:close()
end

以上方法在没有任何限制的情况下是可以使用的。
温馨提示:答案为网友推荐,仅供参考
相似回答