Ruby Forum IronRuby > Socket test

Posted by C.J. Adams-Collier (Guest)
on 09.05.2008 13:20
(Received via mailing list)
Here's a test of the socket patch from Mono at r100:

cjcollier@karma:/usr/src/svn/rubyforge.org/ironruby/trunk/tests/
ironruby$ cat socket-test.rb && echo '===' && ruby socket-test.rb
require 'socket'
streamSock = TCPSocket.new( "127.0.0.1", 20000 )
===
IronRuby.Libraries:0:in `Require': Could not load file or assembly
'socket' or one of its dependencies. The system cannot find the file
specified. (LoadError)

Is this a user error?  Should I add something to the MONO_PATH?
Posted by Peter Bacon Darwin (Guest)
on 09.05.2008 13:39
(Received via mailing list)
Currently the Socket library is part of the IronRuby.Libraries.dll, 
which is
all loaded up on start-up automatically.  So you don't need to do a 
require
'socket' before the TCPSocket class is available.
If you want to write a program that will work on both IronRuby and other
flavours of Ruby then you can do the following at the top of your file.

begin
  Socket
rescue
  require 'socket'
end

which is what appears in my RSpec socket tests at the moment

or perhaps more correctly

begin
  require 'socket'
rescue LoadError
end

Regards,
Pete