Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
winxp multicast socket reading problem
akifusenet
9/7/2007 10:52:00 AM
Hi
I am trying to read some data from a multicast address. So I googled and
found this example.
require 'socket'
require 'ipaddr'
MULTICAST_ADDR = "225.4.5.6"
PORT = 5000
ip = IPAddr.new(MULTICAST_ADDR).hton + IPAddr.new("0.0.0.0").hton
sock = UDPSocket.new
sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
sock.bind(Socket::INADDR_ANY, PORT)
loop do
msg, info = sock.recvfrom(1024)
puts "MSG: #{msg} from #{info[2]} (#{info[3]})/#{info[1]} len
#{msg.size}"
end
It turned out that one-click installer for WinXp(ruby 1.8.6 (2007-03-13
patchlevel 0) [i386-mswin32]) has a bug on Socket::Constants and
Socket::IP_ADD_MEMBERSHIP is not defined.
As explained in
http://rubyforge.org/tracker/?func=detail&group_id=167&aid=9438&am...
I added this line
Socket::IP_ADD_MEMBERSHIP = 12 unless
socket.const_defined?('IP_ADD_MEMBERSHIP')
to the top of my code.
But it didnt work again. Now it says
error on setsockopt:Invalid argument(EINVAL)
What could be the problem?
Thanks in advance.
Akif,
--
Posted via
http://www.ruby-...
.
2 Answers
akifusenet
9/7/2007 11:26:00 AM
0
I tried the same code in Linux. It doesnt give any error. So it has to
be with Windows. Anybody knows how to deal with this?
Thanks.
Akif,
--
Posted via
http://www.ruby-...
.
Eric Rubin
12/7/2007 8:40:00 PM
0
I ran into this same problem and finally discovered that in Windows you
have to call bind before setsockopt. This gets rid of the
"setsockopt:Invalid argument(EINVAL)" message.
Eric Rubin
Akif Tokuz wrote:
>
> Hi
>
> I am trying to read some data from a multicast address. So I googled and
> found this example.
>
> require 'socket'
> require 'ipaddr'
>
> MULTICAST_ADDR = "225.4.5.6"
> PORT = 5000
>
> ip = IPAddr.new(MULTICAST_ADDR).hton + IPAddr.new("0.0.0.0").hton
>
> sock = UDPSocket.new
> sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
> sock.bind(Socket::INADDR_ANY, PORT)
>
> loop do
> msg, info = sock.recvfrom(1024)
> puts "MSG: #{msg} from #{info[2]} (#{info[3]})/#{info[1]} len
> #{msg.size}"
> end
>
> But it didnt work again. Now it says
> error on setsockopt:Invalid argument(EINVAL)
>
> What could be the problem?
>
> Thanks in advance.
>
> Akif,
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
winxp multicast socket reading problem
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password