Last active
December 19, 2015 15:09
-
-
Save cloudwu/5974676 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- main.lua | |
local cell = require "cell" | |
local function accepter(fd, addr, listen_fd) | |
-- can't read fd in this function, because socket.cell haven't forward data from fd | |
local client = cell.cmd("launch", "test.client",fd, addr) | |
-- return cell the data from fd will forward to, you can also return nil for forwarding to self | |
return client | |
end | |
function cell.main() | |
print("[cell main]",cell.self) | |
-- save listen_fd for prevent gc. | |
cell.listen("127.0.0.1:8888",accepter) | |
end | |
-- client | |
local cell = require "cell" | |
function cell.main(fd, addr) | |
local obj = cell.bind(fd) | |
print(addr, "connected", obj, cell.self) | |
cell.fork(function() | |
while true do | |
local line = obj:readline "PING\r\n" | |
if line == nil then | |
break | |
else | |
obj:write("+PONG\r\n") | |
end | |
end | |
cell.exit() | |
end) | |
end | |
---- test | |
-- redis-benchmark -p 8888 -t PING |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment