-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
``` sock:setoption('ip_add_membership', { multiaddr = '224.0.0.2', interface = '0.0.0.0' }) sock:setoption('ip_drop_membership', { multiaddr = '224.0.0.2', interface = '0.0.0.0' }) sock:setoption('ipv6_add_membership', { multiaddr = 'ff02::1', interface = 0 }) sock:setoption('ipv6_drop_membership', { multiaddr = 'ff02::1', interface = 0 }) ``` Signed-off-by: Jianhui Zhao <[email protected]>
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env eco | ||
|
||
local socket = require 'eco.socket' | ||
local sys = require 'eco.sys' | ||
|
||
sys.signal(sys.SIGINT, function() | ||
print('\nGot SIGINT, now quit') | ||
eco.unloop() | ||
end) | ||
|
||
local multicast_addr = '224.0.0.2' | ||
local multicast_port = 8080 | ||
|
||
local sock, err = socket.listen_udp(nil, multicast_port) | ||
if not sock then | ||
error(err) | ||
end | ||
|
||
sock:setoption('ip_add_membership', { multiaddr = multicast_addr }) | ||
|
||
while true do | ||
local data, peer = sock:recvfrom(1024) | ||
print('recvfrom:', peer.ipaddr, peer.port, data) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env eco | ||
|
||
local socket = require 'eco.socket' | ||
local bufio = require 'eco.bufio' | ||
local file = require 'eco.file' | ||
local sys = require 'eco.sys' | ||
|
||
sys.signal(sys.SIGINT, function() | ||
print('\nGot SIGINT, now quit') | ||
eco.unloop() | ||
end) | ||
|
||
local multicast_addr = '224.0.0.2' | ||
local multicast_port = 8080 | ||
|
||
local sock, err = socket.udp() | ||
if not sock then | ||
error(err) | ||
end | ||
|
||
local b = bufio.new(0) | ||
|
||
while true do | ||
file.write(0, 'Please input: ') | ||
|
||
local data = b:read('l') | ||
|
||
if data ~= '' then | ||
sock:sendto(data, multicast_addr, multicast_port) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters