Module: Ronin::Network::Mixins::UDP
- Includes:
- Mixin
- Defined in:
- lib/ronin/network/mixins/udp.rb
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.
Instance Method Summary collapse
-
#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_server {|server| ... } ⇒ UDPServer
protected
Creates a new UDPServer object listening on
server_host
andserver_port
parameters. -
#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.
Methods included from Mixin
Instance Method Details
#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.
100 101 102 103 104 |
# File 'lib/ronin/network/mixins/udp.rb', line 100 def udp_connect(&block) print_info "Connecting to #{self.host}:#{self.port} ..." return ::Net.udp_connect(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.
126 127 128 129 130 131 |
# File 'lib/ronin/network/mixins/udp.rb', line 126 def udp_connect_and_send(data,&block) print_info "Connecting to #{self.host}:#{self.port} ..." print_debug "Sending data: #{data.inspect}" return ::Net.udp_connect_and_send(data,self.host,self.port,self.local_host,self.local_port,&block) end |
#udp_server {|server| ... } ⇒ UDPServer (protected)
Creates a new UDPServer object listening on server_host
and
server_port
parameters.
177 178 179 180 181 182 183 184 185 |
# File 'lib/ronin/network/mixins/udp.rb', line 177 def udp_server(&block) if self.server_host print_info "Listening on #{self.server_host}:#{self.server_port} ..." else print_info "Listening on #{self.server_port} ..." end return ::Net.udp_server(self.server_port,self.server_host,&block) end |
#udp_server_session {|server| ... } ⇒ nil (protected)
Creates a new temporary UDPServer object listening on the
server_host
and server_port
parameters.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/ronin/network/mixins/udp.rb', line 207 def udp_server_session(&block) if self.server_host print_info "Listening on #{self.server_host}:#{self.server_port} ..." else print_info "Listening on #{self.server_port} ..." end ::Net.udp_server_session(&block) if self.server_host print_info "Closed #{self.server_host}:#{self.server_port}" else print_info "Closed #{self.server_port}" end 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.
150 151 152 153 154 155 156 157 |
# File 'lib/ronin/network/mixins/udp.rb', line 150 def udp_session(&block) print_info "Connecting to #{self.host}:#{self.port} ..." ::Net.udp_session(self.host,self.port,self.local_host,self.local_port,&block) print_info "Disconnected from #{self.host}:#{self.port}" return nil end |