diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2009-07-21 14:57:09 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2009-07-21 14:57:09 -0700 |
commit | ca0ac60d048ed34cc39be0414b14a51bb0408b82 (patch) | |
tree | fed7823550adc9ab98e1f705a480db3f430633db /mpdlib.rb | |
parent | 89e03522718985ffd85837caf03f263055fbbd14 (diff) | |
download | ruby-libmpd-ca0ac60d048ed34cc39be0414b14a51bb0408b82.tar.gz ruby-libmpd-ca0ac60d048ed34cc39be0414b14a51bb0408b82.tar.xz |
Add ability to send requests and get responses.
Diffstat (limited to 'mpdlib.rb')
-rw-r--r-- | mpdlib.rb | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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 |