summaryrefslogtreecommitdiff
path: root/tests/modules/socket
diff options
context:
space:
mode:
Diffstat (limited to 'tests/modules/socket')
-rw-r--r--tests/modules/socket/echo_client.lua7
-rw-r--r--tests/modules/socket/echo_server.lua18
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/modules/socket/echo_client.lua b/tests/modules/socket/echo_client.lua
new file mode 100644
index 000000000..fce4ffcff
--- /dev/null
+++ b/tests/modules/socket/echo_client.lua
@@ -0,0 +1,7 @@
+import("core.base.socket")
+
+function main()
+ local sock = socket.connect("127.0.0.1", 9001)
+ print(sock)
+ sock:close()
+end
diff --git a/tests/modules/socket/echo_server.lua b/tests/modules/socket/echo_server.lua
new file mode 100644
index 000000000..76aa9dfb6
--- /dev/null
+++ b/tests/modules/socket/echo_server.lua
@@ -0,0 +1,18 @@
+import("core.base.socket")
+
+function main()
+ local sock = socket.bind("127.0.0.1", 9001)
+ sock:listen(20)
+ local sock_client = nil
+ while true do
+ local ok = sock:wait(socket.EV_ACPT, -1)
+ if ok == socket.EV_ACPT then
+ sock_client = sock:accept()
+ if sock_client then
+ print(sock_client)
+ sock_client:close()
+ end
+ end
+ end
+ sock:close()
+end