Basic SOCKS v4 client implementation
Use as you would any regular connection:
class MyConn < EM::P::Socks4
def post_init send_data("sup") end def receive_data(data) send_data("you said: #{data}") end
end
EM.connect socks_host, socks_port, MyConn, host, port
# File lib/em/protocols/socks4.rb, line 20 20: def initialize(host, port) 21: @host = Socket.gethostbyname(host).last 22: @port = port 23: @socks_error_code = nil 24: @buffer = '' 25: setup_methods 26: end
# File lib/em/protocols/socks4.rb, line 35 35: def restore_methods 36: class << self 37: remove_method :post_init 38: remove_method :receive_data 39: end 40: end
# File lib/em/protocols/socks4.rb, line 28 28: def setup_methods 29: class << self 30: def post_init; socks_post_init; end 31: def receive_data(*a); socks_receive_data(*a); end 32: end 33: end
# File lib/em/protocols/socks4.rb, line 42 42: def socks_post_init 43: header = [4, 1, @port, @host, 0].flatten.pack("CCnA4C") 44: send_data(header) 45: end
# File lib/em/protocols/socks4.rb, line 47 47: def socks_receive_data(data) 48: @buffer << data 49: return if @buffer.size < 8 50: 51: header_resp = @buffer.slice! 0, 8 52: _, r = header_resp.unpack("cc") 53: if r != 90 54: @socks_error_code = r 55: close_connection 56: return 57: end 58: 59: restore_methods 60: 61: post_init 62: receive_data(@buffer) unless @buffer.empty? 63: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.