multicast.bind channel

This commit is contained in:
Cloud Wu
2014-04-28 20:50:00 +08:00
parent 0a40d9c5c6
commit be948c6675
2 changed files with 8 additions and 1 deletions

View File

@@ -20,6 +20,12 @@ function multicast.newchannel(conf)
return channel
end
function multicast.bind(channel, conf)
assert(multicastd, "Init first")
assert(not dispatch[channel])
dispatch[channel] = default_conf(conf)
end
function multicast.publish(channel, ...)
local conf = assert(dispatch[channel])
skynet.call(multicastd, "lua", "PUB", channel, c.pack(conf.pack(...)))

View File

@@ -10,7 +10,7 @@ skynet.start(function()
assert(cmd == "init")
mc.subscribe(channel, {
dispatch = function (channel, source, ...)
print(string.format("%s ===> %s (%d)",skynet.address(source), skynet.address(skynet.self()), channel), ...)
print(string.format("%s <=== %s (%d)",skynet.address(skynet.self()),skynet.address(source), channel), ...)
end
})
end)
@@ -26,6 +26,7 @@ skynet.start(function()
skynet.send(sub, "lua", "init", channel)
end
print(skynet.address(skynet.self()), "===>", channel)
mc.publish(channel, "Hello World")
end)