rewrite watchdog/agent, use new gate

This commit is contained in:
Cloud Wu
2014-04-14 14:21:31 +08:00
parent 476fd10889
commit 1e9a27232b
5 changed files with 151 additions and 58 deletions

View File

@@ -1,5 +1,7 @@
local skynet = require "skynet"
local client = ...
local client
local CMD = {}
skynet.register_protocol {
name = "client",
@@ -8,12 +10,25 @@ skynet.register_protocol {
unpack = skynet.tostring,
dispatch = function (session, address, text)
-- It's client, there is no session
-- skynet.send("LOG", "text", "client message :" .. text)
local result = skynet.call("SIMPLEDB", "text", text)
skynet.ret(result)
end
}
skynet.start(function()
function CMD.start(gate , fd)
client = skynet.launch("client", fd)
skynet.call(gate, "lua", "forward", fd, client)
skynet.send(client,"text","Welcome to skynet")
end
function CMD.exit()
skynet.kill(client)
client = nil
end
skynet.start(function()
skynet.dispatch("lua", function(_,_, command, ...)
local f = CMD[command]
skynet.ret(skynet.pack(f(...)))
end)
end)