Setup management of socket create/close.
[luaevent.git] / luaevent / test / testClient.lua
blob8d14887c5f68bf822fee3c7808103d55bd74fcde
1 require"luaevent"
2 require"socket"
3 local function setupHook(thread)
4 if not thread then debug.sethook(function(event) print("TRACE >: ", debug.getinfo(2, 'n').name) end, 'c')
5 else debug.sethook(thread, function(event) print("TRACE ", thread,">: ", debug.getinfo(2, 'n').name) end, 'c') end
6 end
7 local count = 100
8 local function func(sock)
9 sock = luaevent.wrap(sock)
10 assert(sock:connect("localhost", 20000))
11 for i = 1, 2 do
12 local maxZ = 10
13 for z = 1, maxZ do
14 assert(sock:send("Greet me "))
15 end
16 assert(sock:receive(10 * maxZ))
17 end
18 if skt then skt:close() end
19 count = count - 1
20 if count > 0 then
21 --local sock = assert(socket.tcp())
22 --luaevent.addthread(sock, func, sock)
23 end
24 end
25 for i = 1, 500 do
26 local sock = assert(socket.tcp())
27 luaevent.addthread(sock, func, sock)
28 end
29 luaevent.loop()