uninitialized constant SOCKSSocket

匆匆过客 提交于 2019-12-23 03:34:19

问题


I am running ruby 1.9.3 on a linux box. I would like to use SOCKSSocket, however, I continue to run into the following error:

uninitialized constant SOCKSSocket

simple test using IRB

irb(main):001:0> require 'resolv-replace'
=> true
irb(main):002:0> SOCKSSocket
NameError: uninitialized constant SOCKSSocket
    from (irb):2
    from /usr/local/bin/irb:12:in `<main>'

here is the source code directly from resolv-replace.rb

class SOCKSSocket < TCPSocket
  # :stopdoc:
  alias original_resolv_initialize initialize
  # :startdoc:
  def initialize(host, serv)
    original_resolv_initialize(IPSocket.getaddress(host), port)
  end
end if defined? SOCKSSocket

I can't help but think that I need to install some dependency needed to enable socks or something. Anything would be helpful.


回答1:


SOCKSSocket appears to be an optional component of ruby. That's why resolv-replace only monkey-patches the class if it already exists.

As an illustration, 'net/ftp' defines the following method:

def open_socket(host, port)
  if defined? SOCKSSocket and ENV["SOCKS_SERVER"]
    @passive = true
    return SOCKSSocket.open(host, port)
  else
    return TCPSocket.open(host, port)
  end
end

Perhaps you could do something similar (i.e. create a SOCKS socket if you have SOCKS enabled, otherwise create a boring old TCP socket).

And if you really need the proxy behaviour, a quick google search revealed the following gem: http://socksify.rubyforge.org/ which might be useful.




回答2:


Ok, it seems the configure script does not have --enable-socks as part of it's list of valid options and that is the reason for the WARNING: unrecognized options ...

I did not track down how to add --enable-socks to the list of valid options, however, I did rig the script.

Edit: configure

find the section: Initialize some vars... and add enable_option_checking=no

# Initialize some variables set by options.
enable_option_checking=no

Now, run:

./configure --prefix=/usr/local --enable-socks
make
sudo make install

>ruby --version => 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]

then, try it out in irb

irb(main):001:0> require 'socket'
=> true
irb(main):002:0> require 'resolv-replace'
=> true
irb(main):003:0> SOCKSSocket
=> SOCKSSocket
irb(main):004:0>

I haven't done anything using SOCKSSocket yet, however, at least now it looks like I have it accessible to my code. Also, I assume there is some ENV var to disable option checking or a better way around it. I just did not track that down.

Thanks for your help!!



来源:https://stackoverflow.com/questions/9923704/uninitialized-constant-sockssocket

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!