Skip to content

Commit 723d084

Browse files
committed
add udp sending sample.
1 parent 7c833ae commit 723d084

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

DockerResources/lua/sample_disque_client.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ if not the_id then
1818
the_id = "_empty_"
1919
end
2020

21+
local debug_port = ngx.req.get_headers()["debugport"]
22+
if not debug_port then
23+
-- debugport指定がない場合、通信元をターゲットとしてudp通信を行う。 公式の通信では禁止すべき。
24+
debug_port = ngx.var.remote_addr
25+
end
26+
27+
local udpsock = ngx.socket.udp()
28+
29+
ok, err = udpsock:setpeername(debug_port, 7777)
30+
ngx.log(ngx.ERR, "udpsock ok:", ok, " err:", err, " debug_port:", debug_port)
31+
32+
2133

2234
ip = "127.0.0.1"-- localhost.
2335
port = 7711
@@ -160,6 +172,7 @@ function contextReceiving ()
160172
-- 入れる側にもなんかデータ接続が出ちゃうんだなあ。うーん、、まあでもサーバ側なんでいいや。CopyがN回増えるだけだ。
161173
-- 残る課題は、ここでヘッダを見る、ってことだね。
162174

175+
-- split data with continuation frame if need.
163176
if (localMaxLen < #sendingData) then
164177
local count = math.floor(#sendingData / localMaxLen)
165178
local rest = #sendingData % localMaxLen
@@ -198,6 +211,12 @@ function contextReceiving ()
198211
end
199212

200213
else
214+
do
215+
local ok, err = udpsock:send(sendingData)
216+
ngx.log(ngx.ERR, "udp send ok:", ok, " err:", err)
217+
end
218+
219+
201220
-- send data to client
202221
local bytes, err = localWs:send_binary(sendingData)
203222

0 commit comments

Comments
 (0)