summaryrefslogtreecommitdiff
path: root/tests/modules/socket
diff options
context:
space:
mode:
authorruki <[email protected]>2019-10-15 00:54:17 +0800
committerruki <[email protected]>2019-10-14 23:25:43 +0800
commit7366683acf12cef49d82a37a809c2ed6e5b81459 (patch)
tree23b50d4a87e24700e0dbde44a1729ee705cc053f /tests/modules/socket
parent91bad8e2dbbe495f93cc14b56742d1af55c6d51b (diff)
add socket.accept
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