http {
tcp_nopush off;
tcp_nodelay on;
(省略部分配置)
server {
listen 8080;
(省略部分配置)
location /ws {
content_by_lua '
local server, err = resty.websocket.server:new()
while true do
local data, opcode, err = server:recv_frame()
if not data or opcode == "close" then
break
else
ngx.log(ngx.ERR, "recv " .. opcode .. ": " .. ngx.now())
if opcode == "ping" then
server:send_pong()
ngx.log(ngx.ERR, "send pong: " .. ngx.now())
end
end
end
';
}
location /foo {
content_by_lua '
local client, err = resty.websocket.client:new()
client:connect("ws://127.0.0.1:8080/ws")
client:send_text("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
ngx.log(ngx.ERR, "send text: " .. ngx.now())
local _, err = client:send_ping()
ngx.log(ngx.ERR, "send ping " .. (err and err or "") .. " : " .. ngx.now())
local data, opcode, err = client:recv_frame()
ngx.log(ngx.ERR, "recv " .. (opcode and opcode or err) .. ": " .. ngx.now())
client:close()
';
}
}
}