mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
dispatch must before skynet.start
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user