mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
remove broker and add group command
This commit is contained in:
@@ -3,23 +3,26 @@ local string = string
|
||||
|
||||
local instance = {}
|
||||
|
||||
local function _extract( service, ...)
|
||||
return service , table.concat({...}, " ")
|
||||
end
|
||||
|
||||
skynet.dispatch(function(msg, sz , session, address)
|
||||
local message = skynet.tostring(msg,sz)
|
||||
if session == 0 then
|
||||
-- init notice
|
||||
local reply = instance[address]
|
||||
if reply then
|
||||
skynet.send(reply[2] , reply[1], skynet.address(address))
|
||||
skynet.send(reply[2] , reply[1], skynet.pack(address))
|
||||
instance[address] = nil
|
||||
end
|
||||
else
|
||||
-- launch request
|
||||
local service, param = string.match(message, "([^ ]+) (.*)")
|
||||
local service , param = _extract(skynet.unpack(msg,sz))
|
||||
local inst = skynet.launch(service, param)
|
||||
if inst then
|
||||
instance[inst] = { session, address }
|
||||
else
|
||||
skynet.send(address, session)
|
||||
skynet.send(address, session, skynet.pack(nil))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -5,7 +5,8 @@ skynet.dispatch()
|
||||
skynet.start(function()
|
||||
local group = skynet.query_group(1)
|
||||
for i=1,10 do
|
||||
skynet.newservice("testgroup_c", tostring(i))
|
||||
local address = skynet.newservice("testgroup_c", tostring(i))
|
||||
skynet.enter_group(1 , address)
|
||||
end
|
||||
skynet.send(group,"Hello World")
|
||||
skynet.exit()
|
||||
|
||||
@@ -8,5 +8,4 @@ end
|
||||
|
||||
skynet.start(function()
|
||||
print("start",id)
|
||||
skynet.enter_group(1)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user