Method: MPD#send_command

Defined in:
lib/ruby-mpd.rb

#send_command(command, *args) ⇒ true, ...

Used to send a command to the server, and to recieve the reply. Reply gets parsed. Synchronized on a mutex to be thread safe.

Can be used to get low level direct access to MPD daemon. Not recommended, should be just left for internal use by other methods.

Returns:

  • If “OK” is returned.

  • Parsed response.

Raises:

  • if the command failed.



221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/ruby-mpd.rb', line 221

def send_command(command, *args)
  raise ConnectionError, "Not connected to the server!" if !@socket

  @mutex.synchronize do
    begin
      @socket.puts convert_command(command, *args)
      response = handle_server_response
      return parse_response(command, response)
    rescue Errno::EPIPE
      reset_vars # kill the socket and reset
      raise ConnectionError, 'Broken pipe (got disconnected)'
    end
  end
end