dispatch must before skynet.start

This commit is contained in:
云风
2013-07-02 20:59:17 +08:00
parent 52a4ef8d13
commit fce4b6fee8

View File

@@ -77,29 +77,30 @@ end
local instance = {} local instance = {}
skynet.start(function() skynet.dispatch("text" , function(session, address , cmd)
skynet.dispatch("text" , function(session, address , cmd) if cmd == "" then
if cmd == "" then -- init notice
-- init notice local reply = instance[address]
local reply = instance[address] if reply then
if reply then skynet.redirect(reply.address , 0, "response", reply.session, skynet.address(address))
skynet.redirect(reply.address , 0, "response", reply.session, skynet.address(address)) instance[address] = nil
instance[address] = nil
end
else
-- launch request
local service, param = string.match(cmd,"([^ ]+) (.*)")
local inst = skynet.launch(service, param)
if inst then
services[inst] = cmd
instance[inst] = { session = session, address = address }
else
skynet.ret("")
end
end end
end) else
skynet.dispatch("lua", function(session, address, cmd , ...) -- launch request
cmd = string.upper(cmd) local service, param = string.match(cmd,"([^ ]+) (.*)")
command[cmd](...) local inst = skynet.launch(service, param)
end) if inst then
services[inst] = cmd
instance[inst] = { session = session, address = address }
else
skynet.ret("")
end
end
end) end)
skynet.dispatch("lua", function(session, address, cmd , ...)
cmd = string.upper(cmd)
command[cmd](...)
end)
skynet.start(function() end)