Module: Ronin::Network::Mixins::UDP
Overview
Adds UDP convenience methods and connection parameters to a class.
Defines the following parameters:
host
(String
) - UDP host.port
(Integer
) - UDP port.local_host
(String
) - UDP local host.local_port
(Integer
) - UDP local port.server_host
(String
) - UDP server host.server_port
(Integer
) - UDP server port.
Class Method Summary collapse
-
.host ⇒ Object
UDP host.
-
.host=(value) ⇒ Object
UDP host.
-
.local_host ⇒ Object
UDP local host.
-
.local_host=(value) ⇒ Object
UDP local host.
-
.local_port ⇒ Object
UDP local port.
-
.local_port=(value) ⇒ Object
UDP local port.
-
.port ⇒ Object
UDP port.
-
.port=(value) ⇒ Object
UDP port.
-
.server_host ⇒ Object
UDP server host.
-
.server_host=(value) ⇒ Object
UDP server host.
-
.server_port ⇒ Object
UDP server port.
-
.server_port=(value) ⇒ Object
UDP server port.
Instance Method Summary collapse
-
#host ⇒ Object
UDP host.
-
#host=(value) ⇒ Object
UDP host.
-
#local_host ⇒ Object
UDP local host.
-
#local_host=(value) ⇒ Object
UDP local host.
-
#local_port ⇒ Object
UDP local port.
-
#local_port=(value) ⇒ Object
UDP local port.
-
#port ⇒ Object
UDP port.
-
#port=(value) ⇒ Object
UDP port.
-
#server_host ⇒ Object
UDP server host.
-
#server_host=(value) ⇒ Object
UDP server host.
-
#server_port ⇒ Object
UDP server port.
-
#server_port=(value) ⇒ Object
UDP server port.
-
#udp_connect {|socket| ... } ⇒ UDPSocket
protected
Opens a UDP connection to the host and port specified by the
host
andport
parameters. -
#udp_connect_and_send(data) {|socket| ... } ⇒ UDPSocket
protected
Connects to the host and port specified by the
host
andport
parameters, then sends the given data. -
#udp_open?(timeout = nil) ⇒ Boolean?
protected
Tests whether the UDP port, specified by the
host
andport
parameters, is open. -
#udp_recv {|server, (client_host, client_port), mesg| ... } ⇒ nil
protected
Creates a new UDPServer listening on the
server_host
andserver_port
parameters, accepts only one message from a client. -
#udp_send(data) ⇒ true
protected
Connects to the host and port specified by the
host
andport
parameters, sends the given data and then disconnects. -
#udp_server {|server| ... } ⇒ UDPServer
protected
Creates a new UDPServer object listening on
server_host
andserver_port
parameters. -
#udp_server_loop {|server, (client_host, client_port), mesg| ... } ⇒ nil
protected
Creates a new UDPServer listening on the
server_host
andserver_port
parameters, accepting messages from clients in a loop. -
#udp_server_session {|server| ... } ⇒ nil
protected
Creates a new temporary UDPServer object listening on the
server_host
andserver_port
parameters. -
#udp_session {|socket| ... } ⇒ nil
protected
Creates a UDP session to the host and port specified by the
host
andport
parameters. -
#udp_single_server(&block) ⇒ Object
protected
deprecated
Deprecated.
Deprecated as of 0.5.0. Use #udp_recv instead.
Methods included from Mixin
Methods included from UDP
Class Method Details
.host ⇒ Object
UDP host
42 43 |
# File 'lib/ronin/network/mixins/udp.rb', line 42 parameter :host, :type => String, :description => 'UDP host' |
.host=(value) ⇒ Object
UDP host
42 43 |
# File 'lib/ronin/network/mixins/udp.rb', line 42 parameter :host, :type => String, :description => 'UDP host' |
.local_host ⇒ Object
UDP local host
50 51 |
# File 'lib/ronin/network/mixins/udp.rb', line 50 parameter :local_host, :type => String, :description => 'UDP local host' |
.local_host=(value) ⇒ Object
UDP local host
50 51 |
# File 'lib/ronin/network/mixins/udp.rb', line 50 parameter :local_host, :type => String, :description => 'UDP local host' |
.local_port ⇒ Object
UDP local port
54 55 |
# File 'lib/ronin/network/mixins/udp.rb', line 54 parameter :local_port, :type => Integer, :description => 'UDP local port' |
.local_port=(value) ⇒ Object
UDP local port
54 55 |
# File 'lib/ronin/network/mixins/udp.rb', line 54 parameter :local_port, :type => Integer, :description => 'UDP local port' |
.port ⇒ Object
UDP port
46 47 |
# File 'lib/ronin/network/mixins/udp.rb', line 46 parameter :port, :type => Integer, :description => 'UDP port' |
.port=(value) ⇒ Object
UDP port
46 47 |
# File 'lib/ronin/network/mixins/udp.rb', line 46 parameter :port, :type => Integer, :description => 'UDP port' |
.server_host ⇒ Object
UDP server host
58 59 |
# File 'lib/ronin/network/mixins/udp.rb', line 58 parameter :server_host, :type => String, :description => 'UDP server host' |
.server_host=(value) ⇒ Object
UDP server host
58 59 |
# File 'lib/ronin/network/mixins/udp.rb', line 58 parameter :server_host, :type => String, :description => 'UDP server host' |
Instance Method Details
#host ⇒ Object
UDP host
42 43 |
# File 'lib/ronin/network/mixins/udp.rb', line 42 parameter :host, :type => String, :description => 'UDP host' |
#host=(value) ⇒ Object
UDP host
42 43 |
# File 'lib/ronin/network/mixins/udp.rb', line 42 parameter :host, :type => String, :description => 'UDP host' |
#local_host ⇒ Object
UDP local host
50 51 |
# File 'lib/ronin/network/mixins/udp.rb', line 50 parameter :local_host, :type => String, :description => 'UDP local host' |
#local_host=(value) ⇒ Object
UDP local host
50 51 |
# File 'lib/ronin/network/mixins/udp.rb', line 50 parameter :local_host, :type => String, :description => 'UDP local host' |
#local_port ⇒ Object
UDP local port
54 55 |
# File 'lib/ronin/network/mixins/udp.rb', line 54 parameter :local_port, :type => Integer, :description => 'UDP local port' |
#local_port=(value) ⇒ Object
UDP local port
54 55 |
# File 'lib/ronin/network/mixins/udp.rb', line 54 parameter :local_port, :type => Integer, :description => 'UDP local port' |
#port ⇒ Object
UDP port
46 47 |
# File 'lib/ronin/network/mixins/udp.rb', line 46 parameter :port, :type => Integer, :description => 'UDP port' |
#port=(value) ⇒ Object
UDP port
46 47 |
# File 'lib/ronin/network/mixins/udp.rb', line 46 parameter :port, :type => Integer, :description => 'UDP port' |
#server_host ⇒ Object
UDP server host
58 59 |
# File 'lib/ronin/network/mixins/udp.rb', line 58 parameter :server_host, :type => String, :description => 'UDP server host' |
#server_host=(value) ⇒ Object
UDP server host
58 59 |
# File 'lib/ronin/network/mixins/udp.rb', line 58 parameter :server_host, :type => String, :description => 'UDP server host' |
#server_port ⇒ Object
UDP server port
62 63 |
# File 'lib/ronin/network/mixins/udp.rb', line 62 parameter :server_port, :type => Integer, :description => 'UDP server port' |
#server_port=(value) ⇒ Object
UDP server port
62 63 |
# File 'lib/ronin/network/mixins/udp.rb', line 62 parameter :server_port, :type => Integer, :description => 'UDP server port' |
#udp_connect {|socket| ... } ⇒ UDPSocket (protected)
Opens a UDP connection to the host and port specified by the
host
and port
parameters. If the local_host
and
local_port
parameters are set, they will be used for
the local host and port of the UDP connection.
116 117 118 119 120 |
# File 'lib/ronin/network/mixins/udp.rb', line 116 def udp_connect(&block) print_info "Connecting to #{host_port} ..." return super(self.host,self.port,self.local_host,self.local_port,&block) end |
#udp_connect_and_send(data) {|socket| ... } ⇒ UDPSocket (protected)
Connects to the host and port specified by the host
and port
parameters, then sends the given data. If the local_host
and
local_port
instance methods are set, they will be used for the
local host and port of the UDP connection.
144 145 146 147 148 149 |
# File 'lib/ronin/network/mixins/udp.rb', line 144 def udp_connect_and_send(data,&block) print_info "Connecting to #{host_port} ..." print_debug "Sending data: #{data.inspect}" return super(data,self.host,self.port,self.local_host,self.local_port,&block) end |
#udp_open?(timeout = nil) ⇒ Boolean? (protected)
Tests whether the UDP port, specified by the host
and port
parameters, is open.
82 83 84 85 86 |
# File 'lib/ronin/network/mixins/udp.rb', line 82 def udp_open?(timeout=nil) print_info "Testing if #{host_port} is open ..." super(self.host,self.port,self.local_host,self.local_port,timeout) end |
#udp_recv {|server, (client_host, client_port), mesg| ... } ⇒ nil (protected)
Creates a new UDPServer listening on the server_host
and
server_port
parameters, accepts only one message from a client.
339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/ronin/network/mixins/udp.rb', line 339 def udp_recv(&block) print_info "Listening on #{self.server_host_port} ..." super(self.server_port,self.server_host) do |server,(host,port),mesg| print_info "Received message from #{host}:#{port}" print_debug mesg yield server, [host, port], mesg if block_given? end print_info "Closed #{self.server_host_port}" return nil end |
#udp_send(data) ⇒ true (protected)
Connects to the host and port specified by the host
and port
parameters, sends the given data and then disconnects.
197 198 199 200 201 202 203 204 205 |
# File 'lib/ronin/network/mixins/udp.rb', line 197 def udp_send(data) print_info "Connecting to #{host_port} ..." print_debug "Sending data: #{data.inspect}" super(data,self.host,self.port,self.local_host,self.local_port) print_info "Disconnected from #{host_port}" return true end |
#udp_server {|server| ... } ⇒ UDPServer (protected)
Creates a new UDPServer object listening on server_host
and
server_port
parameters.
227 228 229 230 231 |
# File 'lib/ronin/network/mixins/udp.rb', line 227 def udp_server(&block) print_info "Listening on #{server_host_port} ..." return super(self.server_port,self.server_host,&block) end |
#udp_server_loop {|server, (client_host, client_port), mesg| ... } ⇒ nil (protected)
Creates a new UDPServer listening on the server_host
and
server_port
parameters, accepting messages from clients in a loop.
297 298 299 300 301 302 303 304 |
# File 'lib/ronin/network/mixins/udp.rb', line 297 def udp_server_loop(&block) print_info "Listening on #{self.server_host_port} ..." super(self.server_port,self.server_host,&block) print_info "Closed #{self.server_host_port}" return nil end |
#udp_server_session {|server| ... } ⇒ nil (protected)
Creates a new temporary UDPServer object listening on the
server_host
and server_port
parameters.
255 256 257 258 259 260 261 262 |
# File 'lib/ronin/network/mixins/udp.rb', line 255 def udp_server_session(&block) print_info "Listening on #{self.server_host_port} ..." super(self.server_port,self.server_host,&block) print_info "Closed #{self.server_host_port}" return nil end |
#udp_session {|socket| ... } ⇒ nil (protected)
Creates a UDP session to the host and port specified by the
host
and port
parameters. If the local_host
and local_port
parameters are set, they will be used for the local host and port
of the UDP connection.
170 171 172 173 174 175 176 177 |
# File 'lib/ronin/network/mixins/udp.rb', line 170 def udp_session(&block) print_info "Connecting to #{host_port} ..." super(self.host,self.port,self.local_host,self.local_port,&block) print_info "Disconnected from #{host_port}" return nil end |