Class: EasySockets::UdpServer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#connectionsObject (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

#startObject



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

#stopObject



41
42
43
44
# File 'lib/easy_sockets/udp/udp_server.rb', line 41

def stop
    return unless @started
    @stop_requested = true
end