Class: Af::TCPCommand::Client
- Inherits:
-
Object
- Object
- Af::TCPCommand::Client
- Includes:
- Application::Proxy
- Defined in:
- lib/fiksu-af/tcp_command/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#server_hostname ⇒ Object
readonly
Returns the value of attribute server_hostname.
-
#server_port ⇒ Object
readonly
Returns the value of attribute server_port.
Instance Method Summary collapse
- #command_dispatcher(line) ⇒ Object
- #command_reader ⇒ Object
-
#initialize(server_hostname, server_port) ⇒ Client
constructor
A new instance of Client.
- #logger ⇒ Object
- #ready ⇒ Object
- #reply_to_server(line) ⇒ Object
- #serve ⇒ Object
Methods included from Application::Proxy
Constructor Details
#initialize(server_hostname, server_port) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 7 def initialize(server_hostname, server_port) @server_hostname = server_hostname @server_port = server_port @client = TCPSocket.new(server_hostname, server_port) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 5 def client @client end |
#server_hostname ⇒ Object (readonly)
Returns the value of attribute server_hostname.
5 6 7 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 5 def server_hostname @server_hostname end |
#server_port ⇒ Object (readonly)
Returns the value of attribute server_port.
5 6 7 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 5 def server_port @server_port end |
Instance Method Details
#command_dispatcher(line) ⇒ Object
21 22 23 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 21 def command_dispatcher(line) logger.debug_fine "process command: #{line}" end |
#command_reader ⇒ Object
17 18 19 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 17 def command_reader return client.readline.chomp end |
#logger ⇒ Object
13 14 15 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 13 def logger return af_logger(self.class.name) end |
#ready ⇒ Object
29 30 31 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 29 def ready reply_to_server("ready") end |
#reply_to_server(line) ⇒ Object
25 26 27 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 25 def reply_to_server(line) client.write("#{line}\n") end |
#serve ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fiksu-af/tcp_command/client.rb', line 33 def serve while true logger.debug_medium "READY!" ready begin line = command_reader logger.debug_fine "working on: #{line}" command_dispatcher(line) rescue EOFError logger.warn "master closed connection: #{client.inspect}" client.close break end end end |