blob: f9c99372929f54527cbc7148137e1a75ec217977 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import("core.base.socket")
import("core.base.scheduler")
function _session(addr, port)
print("connect %s:%d ..", addr, port)
local sock = socket.connect(addr, port)
print("%s: connected!", sock)
local count = 0
while count < 10000 do
local send = sock:send("hello world..", {block = true})
if send > 0 then
sock:recv(13, {block = true})
else
break
end
count = count + 1
end
print("%s: send ok, count: %d!", sock, count)
sock:close()
end
function main(count)
count = count and tonumber(count) or 1
for i = 1, count do
scheduler.co_start(_session, "127.0.0.1", 9001)
end
scheduler.runloop()
end
|