Class: Wocket::Server

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO, Bindable
Defined in:
lib/wocket/server.rb

Constant Summary collapse

DEFAULT_HOST =
"127.0.0.1"
DEFAULT_PORT =
9292

Instance Method Summary collapse

Methods included from Bindable

#bind, #trigger

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



13
14
15
16
17
18
19
# File 'lib/wocket/server.rb', line 13

def initialize(options = {})
  @options = options
  @host    = options[:host] || DEFAULT_HOST
  @port    = options[:port] || DEFAULT_PORT

  @callbacks = {}
end

Instance Method Details

#available_bindingsObject



21
22
23
# File 'lib/wocket/server.rb', line 21

def available_bindings
  [:onopen, :onclose, :onerror, :onmessage, :onping, :onpong]
end

#runObject



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

def run
  loop { async.handle_connection @server.accept }
end

#startObject



25
26
27
28
29
# File 'lib/wocket/server.rb', line 25

def start
  @server = TCPServer.new(@host, @port)
  async.run
  puts startup_message
end