Module: Rex::IO::GramServer

Included in:
Proto::DNS::Server
Defined in:
lib/rex/io/gram_server.rb

Overview

This mixin provides the framework and interface for implementing a datagram server that can handle incoming datagrams. Datagram servers include this mixin

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dispatch_request_procObject

This callback procedure can be set and will be called when clients have data to be processed.


85
86
87
# File 'lib/rex/io/gram_server.rb', line 85

def dispatch_request_proc
  @dispatch_request_proc
end

#listener_threadObject

:nodoc:


87
88
89
# File 'lib/rex/io/gram_server.rb', line 87

def listener_thread
  @listener_thread
end

#send_response_procObject

This callback procedure can be set and will be called when clients have data to be processed.


85
86
87
# File 'lib/rex/io/gram_server.rb', line 85

def send_response_proc
  @send_response_proc
end

Instance Method Details

#dispatch_request(client, data) ⇒ Object

This callback is notified when a client connection has data that needs to be processed.


33
34
35
36
37
# File 'lib/rex/io/gram_server.rb', line 33

def dispatch_request(client, data)
  if (dispatch_request_proc)
    dispatch_request_proc.call(client, data)
  end
end

#send_response(client, data) ⇒ Object

This callback is notified when data must be returned to the client

Parameters:

  • client (Socket)

    Client/Socket to receive data

  • data (String)

    Data to be sent to client/socket


43
44
45
46
47
48
49
# File 'lib/rex/io/gram_server.rb', line 43

def send_response(client, data)
  if (send_response_proc)
    send_response_proc.call(client, data)
  else
    client.write(data)
  end
end

#startObject

Start monitoring the listener socket for connections and keep track of all client connections.


55
56
57
58
59
# File 'lib/rex/io/gram_server.rb', line 55

def start
  self.listener_thread = Rex::ThreadFactory.spawn("GramServerListener", false) {
    monitor_listener
  }
end

#stopObject

Terminates the listener monitoring threads and closes all active clients.


64
65
66
# File 'lib/rex/io/gram_server.rb', line 64

def stop
  self.listener_thread.kill
end

#waitObject

This method waits on the server listener thread


71
72
73
# File 'lib/rex/io/gram_server.rb', line 71

def wait
  self.listener_thread.join if self.listener_thread
end