Class: Undead::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/undead/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixed_port = nil, timeout = nil) ⇒ Server



8
9
10
11
12
# File 'lib/undead/server.rb', line 8

def initialize(fixed_port = nil, timeout = nil)
  @fixed_port = fixed_port
  @timeout    = timeout
  start
end

Instance Attribute Details

#fixed_portObject (readonly)

Returns the value of attribute fixed_port.



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

def fixed_port
  @fixed_port
end

#socketObject (readonly)

Returns the value of attribute socket.



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

def socket
  @socket
end

#timeoutObject

Returns the value of attribute timeout.



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

def timeout
  @timeout
end

Instance Method Details

#portObject



14
15
16
# File 'lib/undead/server.rb', line 14

def port
  @socket.port
end

#restartObject



30
31
32
33
# File 'lib/undead/server.rb', line 30

def restart
  stop
  start
end

#send(command) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/undead/server.rb', line 35

def send(command)
  receive_timeout = nil # default
  if command.name == 'visit'
    command.args.push(timeout) # set the client set visit timeout parameter
    receive_timeout = timeout + 5 # Add a couple of seconds to let the client timeout first
  end
  @socket.send(command.id, command.message, receive_timeout) or raise Undead::DeadClient.new(command.message)
end

#startObject



22
23
24
# File 'lib/undead/server.rb', line 22

def start
  @socket = Undead::WebSocketServer.new(fixed_port, timeout)
end

#stopObject



26
27
28
# File 'lib/undead/server.rb', line 26

def stop
  @socket.close
end