Class: EasySockets::UdpServer
- Inherits:
-
Object
- Object
- EasySockets::UdpServer
- Includes:
- ServerUtils
- Defined in:
- lib/easy_sockets/udp/udp_server.rb
Overview
This class was created for testing purposes only. It should not be used in production.
Constant Summary collapse
- DEFAULT_TIMEOUT =
seconds
0.5
Instance Attribute Summary collapse
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ UdpServer
constructor
A new instance of UdpServer.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ UdpServer
Returns a new instance of UdpServer.
18 19 20 21 22 23 24 |
# File 'lib/easy_sockets/udp/udp_server.rb', line 18 def initialize(opts={}) set_opts(opts) @started = false @stop_requested = false @connections = [] register_shutdown_signals end |
Instance Attribute Details
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
14 15 16 |
# File 'lib/easy_sockets/udp/udp_server.rb', line 14 def connections @connections end |
Instance Method Details
#start ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/easy_sockets/udp/udp_server.rb', line 26 def start return if @started @started = true @socket = UDPSocket.new @socket.bind('127.0.0.1', @port) @logger.info "Listening on udp://127.0.0.1:#{@port}" loop do shutdown if @stop_requested # connection = accept_non_block(@socket) # @connections << connection # handle(connection) handle(@socket) end end |
#stop ⇒ Object
41 42 43 44 |
# File 'lib/easy_sockets/udp/udp_server.rb', line 41 def stop return unless @started @stop_requested = true end |