forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestmulticast.lua
40 lines (32 loc) · 937 Bytes
/
testmulticast.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local skynet = require "skynet"
local mc = require "skynet.multicast"
local dc = require "skynet.datacenter"
local mode = ...
if mode == "sub" then
skynet.start(function()
skynet.dispatch("lua", function (_,_, cmd, channel)
assert(cmd == "init")
local c = mc.new {
channel = channel ,
dispatch = function (channel, source, ...)
print(string.format("%s <=== %s %s",skynet.address(skynet.self()),skynet.address(source), channel), ...)
end
}
print(skynet.address(skynet.self()), "sub", c)
c:subscribe()
skynet.ret(skynet.pack())
end)
end)
else
skynet.start(function()
local channel = mc.new()
print("New channel", channel)
for i=1,10 do
local sub = skynet.newservice(SERVICE_NAME, "sub")
skynet.call(sub, "lua", "init", channel.channel)
end
dc.set("MCCHANNEL", channel.channel) -- for multi node test
print(skynet.address(skynet.self()), "===>", channel)
channel:publish("Hello World")
end)
end