diff options
| author | ruki <[email protected]> | 2019-11-03 22:19:55 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-11-03 22:19:55 +0800 |
| commit | 8eddfb0d678d6ea5427ae55e9dff108fde5add42 (patch) | |
| tree | cac98a7120db66447cf48b6b6c1bdf2d05be04a4 /tests/modules/socket | |
| parent | b0a7b7a70cafc7988a33e1856147622b0ea92559 (diff) | |
add socket.sendto and socket.recvfrom
Diffstat (limited to 'tests/modules/socket')
| -rw-r--r-- | tests/modules/socket/udp/echo_client.lua | 10 | ||||
| -rw-r--r-- | tests/modules/socket/udp/echo_server.lua | 14 |
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/modules/socket/udp/echo_client.lua b/tests/modules/socket/udp/echo_client.lua new file mode 100644 index 000000000..2c628cc92 --- /dev/null +++ b/tests/modules/socket/udp/echo_client.lua @@ -0,0 +1,10 @@ +import("core.base.socket") + +function main() + local addr = "127.0.0.1" + local port = 9001 + local sock = socket.udp() + local send = sock:sendto("hello world..", addr, port, {block = true}) + print("%s: send to %s:%d %d bytes!", sock, addr, port, send) + sock:close() +end diff --git a/tests/modules/socket/udp/echo_server.lua b/tests/modules/socket/udp/echo_server.lua new file mode 100644 index 000000000..98cf72f7c --- /dev/null +++ b/tests/modules/socket/udp/echo_server.lua @@ -0,0 +1,14 @@ +import("core.base.socket") + +function main() + local sock = socket.udp() + while true do + print("%s: recv ..", sock) + local recv, data, addr, port = sock:recv(8192, {block = true}) + print("%s: recv: %d bytes from: %s:%d", sock, recv, addr, port) + if data then + data:dump() + end + end + sock:close() +end |
