Class: UState::Server::Backends::TCP

Inherits:
Base
  • Object
show all
Defined in:
lib/ustate/server/backends/tcp.rb

Constant Summary collapse

HOST =
'127.0.0.1'
PORT =
55956

Constants inherited from Base

Base::MAXIMUM_CONNECTIONS, Base::MAX_CONNECTIONS, Base::TIMEOUT

Instance Attribute Summary collapse

Attributes inherited from Base

#maximum_connections, #server, #ssl, #ssl_options, #timeout

Instance Method Summary collapse

Methods inherited from Base

#close, #config, #connection_finished, #empty?, #running?, #size, #ssl?, #start, #stop, #stop!

Constructor Details

#initialize(opts = {}) ⇒ TCP

Returns a new instance of TCP.



12
13
14
15
16
# File 'lib/ustate/server/backends/tcp.rb', line 12

def initialize(opts = {})
  @host = opts[:host] || HOST
  @port = opts[:port] || PORT
  super opts
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/ustate/server/backends/tcp.rb', line 7

def host
  @host
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/ustate/server/backends/tcp.rb', line 7

def port
  @port
end

Instance Method Details

#connectObject

Connect the server



19
20
21
22
# File 'lib/ustate/server/backends/tcp.rb', line 19

def connect
  @server.log.info "Listening on #{@host}:#{@port}"
  @signature = EventMachine.start_server(@host, @port, Connection, &method(:initialize_connection))
end

#disconnectObject

Stops server



25
26
27
# File 'lib/ustate/server/backends/tcp.rb', line 25

def disconnect
  EventMachine.stop_server @signature
end

#to_sObject



29
30
31
# File 'lib/ustate/server/backends/tcp.rb', line 29

def to_s
  "#{@host}:#{@port}"
end