class MPD::Connection

Simple wrapper over Socket

Attributes

host[R]
port[R]
socket[R]

Public Class Methods

new(host: 'localhost', port: 6600) click to toggle source
# File lib/mpd/connection.rb, line 8
def initialize(host: 'localhost', port: 6600)
  @host = host
  @port = port
end

Public Instance Methods

connect() click to toggle source
# File lib/mpd/connection.rb, line 13
def connect
  disconnect if socket
  @socket = TCPSocket.open(host, port)
end
disconnect() click to toggle source
# File lib/mpd/connection.rb, line 18
def disconnect
  socket && socket.close
  @socket = nil
end
gets() click to toggle source
# 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) click to toggle source
# File lib/mpd/connection.rb, line 23
def puts(text)
  raise ConnectionError unless socket
  socket.puts(text)
rescue Errno::ECONNRESET
  raise ConnectionError
end