summaryrefslogtreecommitdiff
path: root/tests/modules/socket/tcp/echo_client.lua
blob: 6c7d6706848965b676b3d7d83efe3ce5dc9cf198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import("core.base.socket")

function main()
    local addr = "127.0.0.1"
    local port = 9001
    print("connect %s:%d ..", addr, port)
    local sock = socket.connect(addr, port)
    if sock then
        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
end