Class: MPD::Connection
- Inherits:
-
Object
- Object
- MPD::Connection
- Defined in:
- lib/mpd/connection.rb
Overview
Simple wrapper over Socket
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
- #gets ⇒ Object
-
#initialize(host: 'localhost', port: 6600) ⇒ Connection
constructor
A new instance of Connection.
- #puts(text) ⇒ Object
Constructor Details
#initialize(host: 'localhost', port: 6600) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 |
# File 'lib/mpd/connection.rb', line 8 def initialize(host: 'localhost', port: 6600) @host = host @port = port end |
Instance Method Details
#connect ⇒ Object
13 14 15 16 |
# File 'lib/mpd/connection.rb', line 13 def connect disconnect if socket @socket = TCPSocket.open(host, port) end |
#disconnect ⇒ Object
18 19 20 21 |
# File 'lib/mpd/connection.rb', line 18 def disconnect socket && socket.close @socket = nil end |
#gets ⇒ Object
30 31 32 33 34 35 |
# File 'lib/mpd/connection.rb', line 30 def gets raise ConnectionError unless socket socket.gets || raise(ConnectionError) rescue Errno::ECONNRESET raise ConnectionError end |
#puts(text) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/mpd/connection.rb', line 23 def puts(text) raise ConnectionError unless socket socket.puts(text) rescue Errno::ECONNRESET raise ConnectionError end |