Class: EventMachine::Protocols::Socks4

### Home Classes Methods

### In Files

- lib/em/protocols/socks4.rb

### Parent

EventMachine::Connection

### Methods

- ::new
- ::post_init
- ::receive_data
- #restore_methods
- #setup_methods
- #socks_post_init
- #socks_receive_data

### Files

- ChangeLog
- DEFERRABLES
- EPOLL
- INSTALL
- KEYBOARD
- LEGAL
- LIGHTWEIGHT_CONCURRENCY
- PURE_RUBY
- RELEASE_NOTES
- SMTP
- SPAWNED_PROCESSES
- TODO

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine
- EventMachine::Channel
- EventMachine::Completion
- EventMachine::Connection
- EventMachine::DNS
- EventMachine::DNS::Request
- EventMachine::DNS::RequestIdAlreadyUsed
- EventMachine::DNS::Resolver
- EventMachine::DNS::Socket
- EventMachine::DatagramObject
- EventMachine::DefaultDeferrable
- EventMachine::Deferrable
- EventMachine::DeferrableChildProcess
- EventMachine::Error
- EventMachine::EvmaKeyboard
- EventMachine::EvmaTCPClient
- EventMachine::EvmaTCPServer
- EventMachine::EvmaUDPSocket
- EventMachine::EvmaUNIXClient
- EventMachine::EvmaUNIXServer
- EventMachine::FileNotFoundException
- EventMachine::FileStreamer
- EventMachine::FileWatch
- EventMachine::Iterator
- EventMachine::LoopbreakReader
- EventMachine::PeriodicTimer
- EventMachine::Pool
- EventMachine::ProcessWatch
- EventMachine::Protocols
- EventMachine::Protocols
- EventMachine::Protocols::HeaderAndContentProtocol
- EventMachine::Protocols::HttpClient
- EventMachine::Protocols::HttpClient2
- EventMachine::Protocols::HttpClient2::Request
- EventMachine::Protocols::LineAndTextProtocol
- EventMachine::Protocols::LineProtocol
- EventMachine::Protocols::LineText2
- EventMachine::Protocols::Memcache
- EventMachine::Protocols::Memcache::ParserError
- EventMachine::Protocols::ObjectProtocol
- EventMachine::Protocols::Postgres3
- EventMachine::Protocols::SASLauth
- EventMachine::Protocols::SASLauthclient
- EventMachine::Protocols::SmtpClient
- EventMachine::Protocols::SmtpServer
- EventMachine::Protocols::Socks4
- EventMachine::Protocols::Stomp
- EventMachine::Protocols::Stomp::Message
- EventMachine::Protocols::TcpConnectTester
- EventMachine::Queue
- EventMachine::Reactor
- EventMachine::Selectable
- EventMachine::SpawnedProcess
- EventMachine::StreamObject
- EventMachine::SystemCmd
- EventMachine::ThreadedResource
- EventMachine::TickLoop
- EventMachine::Timer
- EventMachine::UuidGenerator
- EventMachine::YieldBlockFromSpawnedProcess
- Object
- Object::EM
- Object::P
- BufferedTokenizer
- IO
- StringIO
- TestConnection

No matching classes.

# EventMachine::Protocols::Socks4

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

### Public Class Methods

new(host, port) click to toggle source

    # File lib/em/protocols/socks4.rb, line 20
    def initialize(host, port)
      @host = Socket.gethostbyname(host).last
      @port = port
      @socks_error_code = nil
      @buffer = ''
      setup_methods
    end

post_init() click to toggle source

    # File lib/em/protocols/socks4.rb, line 30
    def post_init; socks_post_init; end

receive_data(*a) click to toggle source

    # File lib/em/protocols/socks4.rb, line 31
    def receive_data(*a); socks_receive_data(*a); end

### Public Instance Methods

restore_methods() click to toggle source

    # File lib/em/protocols/socks4.rb, line 35
    def restore_methods
      class << self
        remove_method :post_init
        remove_method :receive_data
      end
    end

setup_methods() click to toggle source

    # File lib/em/protocols/socks4.rb, line 28
    def setup_methods
      class << self
        def post_init; socks_post_init; end
        def receive_data(*a); socks_receive_data(*a); end
      end
    end

socks_post_init() click to toggle source

    # File lib/em/protocols/socks4.rb, line 42
    def socks_post_init
      header = [4, 1, @port, @host, 0].flatten.pack("CCnA4C")
      send_data(header)
    end

socks_receive_data(data) click to toggle source

    # File lib/em/protocols/socks4.rb, line 47
    def socks_receive_data(data)
      @buffer << data
      return  if @buffer.size < 8

      header_resp = @buffer.slice! 0, 8
      _, r = header_resp.unpack("cc")
      if r != 90
        @socks_error_code = r
        close_connection
        return
      end

      restore_methods

      post_init
      receive_data(@buffer)  unless @buffer.empty?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.