blob: 27dccfc7dfa2114e8cd1ad60ec9626394de135ad (
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
29
30
31
32
|
import("core.base.socket")
import("core.base.bytes")
function main()
local addr = "127.0.0.1"
local port = 9092
print("connect %s:%d ..", addr, port)
local sock = socket.connect(addr, port)
print("%s: connected!", sock)
local real = 0
local recv = 0
local data = nil
local wait = false
local buff = bytes(8192)
while true do
real, data = sock:recv(buff, 8192)
if real > 0 then
recv = recv + real
wait = false
elseif real == 0 and not wait then
if sock:wait(socket.EV_RECV, -1) == socket.EV_RECV then
wait = true
else
break
end
else
break
end
end
print("%s: recv ok, size: %d!", sock, recv)
sock:close()
end
|