From 4c2a04eded5c66c6696d4b53aee339f0f3ab8155 Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Fri, 31 Aug 2007 09:34:09 -0400 Subject: Reformed project layout from 'luaevent/*' -> '*' --- test/test.lua | 34 ++++++++++++++++++++++++++++++++++ test/testClient.lua | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 test/test.lua create mode 100644 test/testClient.lua (limited to 'test') diff --git a/test/test.lua b/test/test.lua new file mode 100644 index 0000000..412857e --- /dev/null +++ b/test/test.lua @@ -0,0 +1,34 @@ +-- Tests Copas with a simple Echo server +-- +-- Run the test file and the connect to the server by telnet on the used port +-- to stop the test just send the command "quit" + +require"luaevent" +require"socket" +local oldPrint = print +print = function(...) + oldPrint("SRV", ...) +end + +local function echoHandler(skt) + while true do + local data,ret = luaevent.receive(skt, 10) + --print("GOT: ", data, ret) + if data == "quit" or ret == 'closed' then + break + end + luaevent.send(skt, data) + collectgarbage() + end + skt:close() + --print("DONE") +end +local server = assert(socket.bind("localhost", 20000)) +server:settimeout(0) +local coro = coroutine.create +coroutine.create = function(...) + local ret = coro(...) + return ret +end +luaevent.addserver(server, echoHandler) +luaevent.loop() diff --git a/test/testClient.lua b/test/testClient.lua new file mode 100644 index 0000000..fbbcf87 --- /dev/null +++ b/test/testClient.lua @@ -0,0 +1,19 @@ +require"luaevent" +require"socket" +local oldPrint = print +print = function(...) + oldPrint("CLT", ...) +end + +local function func() + print("ACTIVATED") + local sock = socket.tcp() + --sock: + sock = luaevent.wrap(sock) + print(assert(sock:connect("localhost", 20000))) + for i = 1, 100 do assert(sock:send("Greet me ")) assert(sock:receive(10)) collectgarbage() end +end + +luaevent.addthread(func) + +luaevent.loop() \ No newline at end of file -- cgit v1.2.3