udpmulticast 0.0.1
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/lib/udpmulticast.rb +41 -0
- metadata +67 -0
data/lib/udpmulticast.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'ipaddr'
|
3
|
+
|
4
|
+
class UDPMulticast
|
5
|
+
def initialize(multicast_addr = '233.185.223.1', port = 553, ttl = 1)
|
6
|
+
@multicast_addr = multicast_addr
|
7
|
+
@port = port
|
8
|
+
@ttl = ttl
|
9
|
+
@server = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def server
|
13
|
+
@server
|
14
|
+
end
|
15
|
+
|
16
|
+
def run!
|
17
|
+
create_socket
|
18
|
+
socket_opt Socket::IP_ADD_MEMBERSHIP, multicast_member
|
19
|
+
socket_opt Socket::IP_MULTICAST_TTL, @ttl
|
20
|
+
socket_opt Socket::IP_TTL, @ttl
|
21
|
+
bind
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def multicast_member
|
27
|
+
IPAddr.new(@multicast_addr).hton + IPAddr.new('0.0.0.0').hton
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_socket
|
31
|
+
@server = UDPSocket.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def socket_opt(opt, val)
|
35
|
+
@server.setsockopt Socket::IPPROTO_IP, opt, val
|
36
|
+
end
|
37
|
+
|
38
|
+
def bind
|
39
|
+
@server.bind Socket::INADDR_ANY, @port
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: udpmulticast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Donatas Abraitis
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2016-03-05 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Simple class for using UDP with Multicast
|
23
|
+
email: donatas.abraitis@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/udpmulticast.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://rubygems.org/gems/udpmulticast
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.7
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: UDP Multicast
|
66
|
+
test_files: []
|
67
|
+
|