D
Daemon Le
Hi,
I'm trying to "listen" on a multicast using Ruby. After trolling the
news groups and "google", I was able to find a rudimentary set of code in
my attempt to listen on multicasting, but it doesn't quite work and I
don't know why? Does anyone know of good resources (webpage or book) for
multicasting with Ruby? Any help would be appreciated.
Here's the sample code that "semi" works...
--- begin ------------------------------------
require 'socket'
port = 1212
addr = '228.5.6.8'
host = Socket.gethostname
maddr = addr.split('.').collect! { |b| b.to_i }.pack('CCCC')
mreq = maddr + Socket.gethostbyname(host)[3]
sock = UDPSocket.new
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, mreq)
sock.bind(host, port)
sock.connect(host, port)
# Check send ...
sock.send('Hello', 0, addr, port)
sock.send('World', 0, addr, port)
# Check listen ...
count=0
5.times {
count += 1
p "COUNT = #{count}"
p sock.recvfrom(8)
}
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_DROP_MEMBERSHIP, mreq)
exit( 0 )
--- end --------------------------------------
The "Check send" works just fine to send into the multicast address. I
check this while listening with tcpdump (i.e., tcpdump 'ip multicast and
src port 1212 and host 228.5.6.8'). But I'm unable to pick up on the
"Check listen" part. It just basically hangs with "COUNT = 1" and waits
forever even though I can clearly see packets being transmitted over the
multicast address in question.
FYI. I'm starting to look at the "rb_spread" module, but I would rather
try to do this without first...
- Daemon
I'm trying to "listen" on a multicast using Ruby. After trolling the
news groups and "google", I was able to find a rudimentary set of code in
my attempt to listen on multicasting, but it doesn't quite work and I
don't know why? Does anyone know of good resources (webpage or book) for
multicasting with Ruby? Any help would be appreciated.
Here's the sample code that "semi" works...
--- begin ------------------------------------
require 'socket'
port = 1212
addr = '228.5.6.8'
host = Socket.gethostname
maddr = addr.split('.').collect! { |b| b.to_i }.pack('CCCC')
mreq = maddr + Socket.gethostbyname(host)[3]
sock = UDPSocket.new
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, mreq)
sock.bind(host, port)
sock.connect(host, port)
# Check send ...
sock.send('Hello', 0, addr, port)
sock.send('World', 0, addr, port)
# Check listen ...
count=0
5.times {
count += 1
p "COUNT = #{count}"
p sock.recvfrom(8)
}
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_DROP_MEMBERSHIP, mreq)
exit( 0 )
--- end --------------------------------------
The "Check send" works just fine to send into the multicast address. I
check this while listening with tcpdump (i.e., tcpdump 'ip multicast and
src port 1212 and host 228.5.6.8'). But I'm unable to pick up on the
"Check listen" part. It just basically hangs with "COUNT = 1" and waits
forever even though I can clearly see packets being transmitted over the
multicast address in question.
FYI. I'm starting to look at the "rb_spread" module, but I would rather
try to do this without first...
- Daemon