Class: Arbi::Client
- Inherits:
-
Object
- Object
- Arbi::Client
- Defined in:
- lib/arbi/client.rb
Instance Attribute Summary collapse
-
#sock ⇒ Object
readonly
Returns the value of attribute sock.
Instance Method Summary collapse
- #connect ⇒ Object
- #get(what = 'help') ⇒ Object
-
#initialize(address = '127.0.0.1', port = 6969) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(address = '127.0.0.1', port = 6969) ⇒ Client
Returns a new instance of Client.
28 29 30 31 32 33 |
# File 'lib/arbi/client.rb', line 28 def initialize(address = '127.0.0.1', port = 6969) @address = address || '127.0.0.1' @port = port || 6969 self.connect end |
Instance Attribute Details
#sock ⇒ Object (readonly)
Returns the value of attribute sock.
26 27 28 |
# File 'lib/arbi/client.rb', line 26 def sock @sock end |
Instance Method Details
#connect ⇒ Object
35 36 37 38 |
# File 'lib/arbi/client.rb', line 35 def connect @sock = TCPSocket.new(@address, @port) @sock.gets end |
#get(what = 'help') ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/arbi/client.rb', line 40 def get(what = 'help') @sock.print "#{what.strip}\r\n" @sock.flush JSON.parse(@sock.gets.strip, create_additions: true) rescue Errno::EPIPE self.connect retry rescue NoMethodError nil end |