Module: TextProtocols

Defined in:
lib/text_protocols.rb,
lib/text_protocols/version.rb

Defined Under Namespace

Classes: Protocol, Server

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.log(string) ⇒ Object



28
29
30
31
# File 'lib/text_protocols.rb', line 28

def self.log string
  puts string
  $stdout.flush
end

.set_signals_hooksObject



11
12
13
14
15
16
17
18
# File 'lib/text_protocols.rb', line 11

def self.set_signals_hooks
  ['SIGINT', 'SIGTERM'].each do |signal|
    Signal.trap signal do
      log "Bye!"
      exit
    end
  end
end

.start(port = '5000', bind = '127.0.0.1', &block) ⇒ Object



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

def self.start port='5000', bind='127.0.0.1', &block
  set_signals_hooks
  start_server port, bind, block
end

.start_server(port, bind, block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/text_protocols.rb', line 20

def self.start_server port, bind, block
  server = Server.config port, bind, &block
  server.start
  sleep
rescue Interrupt
  log "Server was interrupted..."
end