diff options
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 |
