Hi,
I am having trouble with sockets on my development machine (windows &
cygwin). I''ve done a quick test on a linux box and it
doesn''t seem to
show the same behaviour, i.e. it works.
Can someone explain why the following error is thrown on windows and not
on linux and if there is a workaround to fix it.
--environment.rb----
##define a socket. I am defining it in environment.rb because I am
going to use the socket in some of the models & also a script (running
via script/runner)
begin
$socket = UDPSocket.open
$socket.bind("",1680)
rescue Errno::EADDRINUSE
puts "Error: #{$!}"
end
Open two consoles:
----Console 1-----
$ ./script/console
Loading development environment (Rails 2.0.2)>> $socket
=> #<UDPSocket:0x2b5c71558e80>
----Console 2-----
$ ./script/console
Loading development environment (Rails 2.0.2)
Error: Address already in use - bind(2)>> $socket
=> #<UDPSocket:0x2b5c71558e80>>> $socket.recvfrom(512)
Errno::EINVAL: Invalid argument - recvfrom(2)
from (irb):1:in `recvfrom''
from (irb):1
Why can the second console see the socket but throw an error when I try
and use it. Linux doesn''t seem to do this, i.e. I can use the socket
in
either window.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Feb-29 12:29 UTC
Re: Socket problem, Errno::EINVAL. Can someone explain?
On 29 Feb 2008, at 12:02, Tim Conner wrote:> > Hi, > I am having trouble with sockets on my development machine (windows & > cygwin). I''ve done a quick test on a linux box and it doesn''t seem > to > show the same behaviour, i.e. it works. > Can someone explain why the following error is thrown on windows and > not > on linux and if there is a workaround to fix it. > > --environment.rb---- > ##define a socket. I am defining it in environment.rb because I am > going to use the socket in some of the models & also a script (running > via script/runner) > begin > $socket = UDPSocket.open > $socket.bind("",1680) > rescue Errno::EADDRINUSE > puts "Error: #{$!}" > end > > Open two consoles: > ----Console 1----- > $ ./script/console > Loading development environment (Rails 2.0.2) >>> $socket > => #<UDPSocket:0x2b5c71558e80> > > ----Console 2----- > $ ./script/console > Loading development environment (Rails 2.0.2) > Error: Address already in use - bind(2) >>> $socket > => #<UDPSocket:0x2b5c71558e80> >>> $socket.recvfrom(512) > Errno::EINVAL: Invalid argument - recvfrom(2) > from (irb):1:in `recvfrom'' > from (irb):1 > >The exception occurs when you bind the socket, not when you create it, so $socket exists in both cases, it''s just not bound in the second console. Fred> Why can the second console see the socket but throw an error when I > try > and use it. Linux doesn''t seem to do this, i.e. I can use the > socket in > either window. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---