mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 11:33:09 +00:00
local multicast support
This commit is contained in:
32
test/testmulticast.lua
Normal file
32
test/testmulticast.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local skynet = require "skynet"
|
||||
local mc = require "multicast"
|
||||
|
||||
local mode = ...
|
||||
|
||||
if mode == "sub" then
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("lua", function (_,_, cmd, channel)
|
||||
assert(cmd == "init")
|
||||
mc.subscribe(channel, {
|
||||
dispatch = function (channel, source, ...)
|
||||
print(string.format("%s ===> %s (%d)",skynet.address(source), skynet.address(skynet.self()), channel), ...)
|
||||
end
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
||||
else
|
||||
|
||||
skynet.start(function()
|
||||
local channel = mc.newchannel()
|
||||
print("New channel", channel)
|
||||
for i=1,10 do
|
||||
local sub = skynet.newservice("testmulticast", "sub")
|
||||
skynet.send(sub, "lua", "init", channel)
|
||||
end
|
||||
|
||||
mc.publish(channel, "Hello World")
|
||||
end)
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user