Class: Fnord::TCPConnection
- Inherits:
-
Object
- Object
- Fnord::TCPConnection
- Defined in:
- lib/fnord/tcp_connection.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
-
#initialize(host, port = 1337, options = {}) ⇒ TCPConnection
constructor
A new instance of TCPConnection.
- #reconnect ⇒ Object
- #send_data(data) ⇒ Object
Constructor Details
#initialize(host, port = 1337, options = {}) ⇒ TCPConnection
Returns a new instance of TCPConnection.
6 7 8 |
# File 'lib/fnord/tcp_connection.rb', line 6 def initialize(host, port = 1337, = {}) @host, @port, @options = host, port, end |
Instance Attribute Details
#socket ⇒ Object
Returns the value of attribute socket.
4 5 6 |
# File 'lib/fnord/tcp_connection.rb', line 4 def socket @socket end |
Instance Method Details
#connect ⇒ Object
18 19 20 |
# File 'lib/fnord/tcp_connection.rb', line 18 def connect @socket = TCPSocket.new(@host, @port) end |
#connected? ⇒ Boolean
40 41 42 |
# File 'lib/fnord/tcp_connection.rb', line 40 def connected? !!@socket end |
#disconnect ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fnord/tcp_connection.rb', line 28 def disconnect # untested return unless connected? begin @socket.close rescue ensure @socket = nil end end |
#reconnect ⇒ Object
22 23 24 25 26 |
# File 'lib/fnord/tcp_connection.rb', line 22 def reconnect # untested disconnect connect end |
#send_data(data) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/fnord/tcp_connection.rb', line 10 def send_data(data) ensure_connected(:retry => true) do # Rails.logger.info "[FNORD] Sending data\n#{data}" @socket.puts(data) @socket.flush end end |