Class: OkGntpd

Inherits:
Object
  • Object
show all
Defined in:
lib/ok_gntpd.rb,
lib/ok_gntpd/version.rb

Constant Summary collapse

VERSION =
"0.0.5"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ OkGntpd

Returns a new instance of OkGntpd.



18
19
20
21
# File 'lib/ok_gntpd.rb', line 18

def initialize(options = nil)
  @options = self.class.default_options.merge(options || {})
  @status = :stop
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/ok_gntpd.rb', line 16

def options
  @options
end

#statusObject (readonly)

Returns the value of attribute status.



16
17
18
# File 'lib/ok_gntpd.rb', line 16

def status
  @status
end

Class Method Details

.default_optionsObject



10
11
12
13
14
# File 'lib/ok_gntpd.rb', line 10

def self.default_options
  {
    :port   => 23053
  }
end

.start(options = nil) ⇒ Object



6
7
8
# File 'lib/ok_gntpd.rb', line 6

def self.start(options = nil)
  new(options).start
end

Instance Method Details

#startObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ok_gntpd.rb', line 23

def start
  port = @options[:port]
  puts "Start listening GNTP on #{port}."

  gate = TCPServer.open(port)
  begin
    @status = :start
    loop do
      sock = gate.accept
      sock.write <<EOS
GNTP/1.0 -OK NONE\r
\r
EOS
      sock.close
    end
  ensure
    gate.close
    @status = :stop
    puts "Closed."
  end
end