multicast 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +15 -11
- data/VERSION +1 -1
- data/bin/mclisten +30 -22
- data/bin/mcsend +56 -0
- data/lib/multicast/listener.rb +34 -0
- data/lib/multicast/sender.rb +22 -0
- data/lib/multicast.rb +4 -1
- data/multicast.gemspec +6 -4
- metadata +9 -5
data/README.rdoc
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
= multicast
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
Ruby library and command line utils for multicasting
|
4
|
+
|
5
|
+
This project is very young so some things might not work.
|
6
|
+
|
7
|
+
== Listening
|
8
|
+
|
9
|
+
mclisten -g 224.0.1.33 -p 4567
|
10
|
+
|
11
|
+
== Sending
|
12
|
+
|
13
|
+
mcsend -g 224.0.1.33 -p 4567 -m "Multicasting like a champ"
|
14
|
+
|
15
|
+
== Contact
|
16
|
+
|
17
|
+
You can find me on @mwhuss[http://twitter.com/mwhuss]
|
14
18
|
|
15
19
|
== Copyright
|
16
20
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/mclisten
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require File.dirname(__FILE__) + '/../lib/multicast'
|
4
4
|
require 'choice'
|
5
5
|
|
6
|
-
|
6
|
+
PROGRAM_VERSION = File.exist?('VERSION') ? File.read('VERSION') : ""
|
7
7
|
|
8
8
|
|
9
9
|
Choice.options do
|
@@ -38,33 +38,41 @@ Choice.options do
|
|
38
38
|
long '--version'
|
39
39
|
desc 'Show version'
|
40
40
|
action do
|
41
|
-
puts "
|
41
|
+
puts "mclisten v#{PROGRAM_VERSION}"
|
42
42
|
exit
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
47
|
puts "==== Multicast Listener ====\n"
|
48
|
+
listener = Multicast::Listener.new(:group => Choice.choices[:group], :port => Choice.choices[:port])
|
49
|
+
puts "---> Joining #{Choice.choices[:group]}:#{Choice.choices[:port]}"
|
49
50
|
|
50
|
-
|
51
|
-
port = Choice.choices[:port]
|
52
|
-
ip = IPAddr.new(multicast_group).hton + IPAddr.new("0.0.0.0").hton
|
53
|
-
puts "---> Joining #{multicast_group}:#{port}"
|
54
|
-
sock = UDPSocket.new
|
55
|
-
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
|
56
|
-
sock.bind(Socket::INADDR_ANY, port)
|
57
|
-
|
58
|
-
loop do
|
59
|
-
begin
|
60
|
-
msg, info = sock.recvfrom(1024)
|
61
|
-
#puts "MSG: #{msg} from #{info[2]} (#{info[3]})/#{info[1]} len #{msg.size}"
|
51
|
+
listener.listen do |msg, info|
|
62
52
|
puts "---> [#{info[2]} / #{info[3]}:#{info[1]} (#{msg.size} bytes)] #{msg}"
|
63
|
-
|
64
|
-
|
65
|
-
sock.close
|
66
|
-
puts "\n---> Exiting"
|
67
|
-
exit
|
68
|
-
end
|
53
|
+
end
|
54
|
+
|
69
55
|
|
70
|
-
|
56
|
+
# puts "==== Multicast Listener ====\n"
|
57
|
+
#
|
58
|
+
# multicast_group = Choice.choices[:group]
|
59
|
+
# port = Choice.choices[:port]
|
60
|
+
# ip = IPAddr.new(multicast_group).hton + IPAddr.new("0.0.0.0").hton
|
61
|
+
# puts "---> Joining #{multicast_group}:#{port}"
|
62
|
+
# sock = UDPSocket.new
|
63
|
+
# sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
|
64
|
+
# sock.bind(Socket::INADDR_ANY, port)
|
65
|
+
#
|
66
|
+
# loop do
|
67
|
+
# begin
|
68
|
+
# msg, info = sock.recvfrom(1024)
|
69
|
+
# #puts "MSG: #{msg} from #{info[2]} (#{info[3]})/#{info[1]} len #{msg.size}"
|
70
|
+
# puts "---> [#{info[2]} / #{info[3]}:#{info[1]} (#{msg.size} bytes)] #{msg}"
|
71
|
+
#
|
72
|
+
# rescue Interrupt
|
73
|
+
# sock.close
|
74
|
+
# puts "\n---> Exiting"
|
75
|
+
# exit
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# end
|
data/bin/mcsend
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../lib/multicast'
|
4
|
+
require 'choice'
|
5
|
+
|
6
|
+
PROGRAM_VERSION = File.exist?('VERSION') ? File.read('VERSION') : ""
|
7
|
+
|
8
|
+
Choice.options do
|
9
|
+
header ''
|
10
|
+
header 'Specific options:'
|
11
|
+
|
12
|
+
option :group, :required => true do
|
13
|
+
short '-g'
|
14
|
+
long '--group=GROUP'
|
15
|
+
desc 'The multicast group to send to'
|
16
|
+
end
|
17
|
+
|
18
|
+
option :port, :required => true do
|
19
|
+
short '-p'
|
20
|
+
long '--port=PORT'
|
21
|
+
desc 'The port to send on'
|
22
|
+
cast Integer
|
23
|
+
end
|
24
|
+
|
25
|
+
option :message do
|
26
|
+
short '-m'
|
27
|
+
long '--message=MESSAGE'
|
28
|
+
desc 'The message to send to the multicast group'
|
29
|
+
default "Multicast Message from Ruby Multicast lib"
|
30
|
+
end
|
31
|
+
|
32
|
+
separator ''
|
33
|
+
separator 'Common options: '
|
34
|
+
|
35
|
+
option :help do
|
36
|
+
long '--help'
|
37
|
+
desc 'Show this message'
|
38
|
+
end
|
39
|
+
|
40
|
+
option :version do
|
41
|
+
short '-v'
|
42
|
+
long '--version'
|
43
|
+
desc 'Show version'
|
44
|
+
action do
|
45
|
+
puts "mcsend v#{PROGRAM_VERSION}"
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "==== Multicast Sender ====\n"
|
52
|
+
sender = Multicast::Sender.new(:group => Choice.choices[:group], :port => Choice.choices[:port])
|
53
|
+
puts "---> Sending message to #{Choice.choices[:group]}:#{Choice.choices[:port]}"
|
54
|
+
puts "---> #{Choice.choices[:message]}"
|
55
|
+
|
56
|
+
sender.send(Choice.choices[:message])
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Multicast
|
2
|
+
class Listener
|
3
|
+
attr_accessor :group, :port
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
@group = opts[:group]
|
7
|
+
@port = opts[:port]
|
8
|
+
end
|
9
|
+
|
10
|
+
def listen(&block)
|
11
|
+
|
12
|
+
ip = IPAddr.new(@group).hton + IPAddr.new("0.0.0.0").hton
|
13
|
+
sock = UDPSocket.new
|
14
|
+
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
|
15
|
+
sock.bind(Socket::INADDR_ANY, @port)
|
16
|
+
|
17
|
+
loop do
|
18
|
+
begin
|
19
|
+
msg, info = sock.recvfrom(1024)
|
20
|
+
#puts "MSG: #{msg} from #{info[2]} (#{info[3]})/#{info[1]} len #{msg.size}"
|
21
|
+
#puts "---> [#{info[2]} / #{info[3]}:#{info[1]} (#{msg.size} bytes)] #{msg}"
|
22
|
+
yield(msg, info)
|
23
|
+
|
24
|
+
rescue Interrupt
|
25
|
+
sock.close
|
26
|
+
puts "\n---> Exiting"
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Multicast
|
2
|
+
class Sender
|
3
|
+
attr_accessor :group, :port
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
@group = opts[:group]
|
7
|
+
@port = opts[:port]
|
8
|
+
end
|
9
|
+
|
10
|
+
def send(message)
|
11
|
+
|
12
|
+
begin
|
13
|
+
socket = UDPSocket.open
|
14
|
+
socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [1].pack('i'))
|
15
|
+
socket.send(message, 0, @group, @port)
|
16
|
+
ensure
|
17
|
+
socket.close
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/multicast.rb
CHANGED
data/multicast.gemspec
CHANGED
@@ -5,15 +5,14 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{multicast}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marshall Huss"]
|
12
|
-
s.date = %q{2010-05-
|
13
|
-
s.default_executable = %q{mclisten}
|
12
|
+
s.date = %q{2010-05-20}
|
14
13
|
s.description = %q{Multicasting in Ruby}
|
15
14
|
s.email = %q{mwhuss@gmail.com}
|
16
|
-
s.executables = ["mclisten"]
|
15
|
+
s.executables = ["mclisten", "mcsend"]
|
17
16
|
s.extra_rdoc_files = [
|
18
17
|
"LICENSE",
|
19
18
|
"README.rdoc"
|
@@ -26,7 +25,10 @@ Gem::Specification.new do |s|
|
|
26
25
|
"Rakefile",
|
27
26
|
"VERSION",
|
28
27
|
"bin/mclisten",
|
28
|
+
"bin/mcsend",
|
29
29
|
"lib/multicast.rb",
|
30
|
+
"lib/multicast/listener.rb",
|
31
|
+
"lib/multicast/sender.rb",
|
30
32
|
"multicast.gemspec",
|
31
33
|
"test/helper.rb",
|
32
34
|
"test/test_multicast.rb"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multicast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marshall Huss
|
@@ -15,8 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
19
|
-
default_executable:
|
18
|
+
date: 2010-05-20 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: thoughtbot-shoulda
|
@@ -52,6 +52,7 @@ description: Multicasting in Ruby
|
|
52
52
|
email: mwhuss@gmail.com
|
53
53
|
executables:
|
54
54
|
- mclisten
|
55
|
+
- mcsend
|
55
56
|
extensions: []
|
56
57
|
|
57
58
|
extra_rdoc_files:
|
@@ -65,7 +66,10 @@ files:
|
|
65
66
|
- Rakefile
|
66
67
|
- VERSION
|
67
68
|
- bin/mclisten
|
69
|
+
- bin/mcsend
|
68
70
|
- lib/multicast.rb
|
71
|
+
- lib/multicast/listener.rb
|
72
|
+
- lib/multicast/sender.rb
|
69
73
|
- multicast.gemspec
|
70
74
|
- test/helper.rb
|
71
75
|
- test/test_multicast.rb
|