From ca0ac60d048ed34cc39be0414b14a51bb0408b82 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 21 Jul 2009 14:57:09 -0700 Subject: Add ability to send requests and get responses. --- mpdlib.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mpdlib.rb b/mpdlib.rb index 33c0585..c8266be 100644 --- a/mpdlib.rb +++ b/mpdlib.rb @@ -17,4 +17,23 @@ class MPD @socket = TCPSocket.new @host, @port return @socket.gets.chomp end + + def send_request command + # Escape backslashes in command. + @socket.puts command.sub('\\', '\\\\\\') + return get_response + end + + def get_response + response = String.new + + while true + line = @socket.gets + + return response if line == "OK\n" + return false if line =~ /^ACK/ + + response << line + end + end end -- cgit v1.2.3-70-g09d2