Reading a returned code from socket and httpq


O

Osuka Adartse

I have a question regarding sockets, I'm trying to use the HttpQ plugin
so open a socket to host x at 4800 plus passwd, and send commands, so
far so good(commands working), but I'm having trouble figuring how to
read the returned code.

All I keep getting is:"HTTP/1.0 200 OK\r\nServer: Winamp httpQ Plugin
Version 2.1\r\nContent-Type: text/html\r\n\r\n"
at the end of this string there should be a return code like:

" 1" or " 5353. Singyguy - sillysong"

but there's nothing, so anybody have an idea how to do this?

-some code-
require 'socket'
passw='*****'
hostname='localhost'
port=4800
sock=TCPSocket.new(hostname,port)

sock.send("GET /PLAY?p=#{passw} HTTP/1.0\r\n\r\n",0)
#executes the command, but no return code,there should be an 1 at the
end of the str
puts sock.recv(128).inspect
#=>"HTTP/1.0 200 OK\r\nServer: Winamp httpQ Plugin Version
2.1\r\nContent-Type: text/html\r\n\r\n"

sock.send("GET /GETCURRENTTITLE?p=#{@passw}&a=1 HTTP/1.0\r\n\r\n",0)
puts sock.recv(128).inspect #=> should return something like:
#=>"HTTP/1.0 200 OK\r\nServer: Winamp httpQ Plugin Version
2.1\r\nContent-Type: text/html\r\n\r\n" 2080. Artist - Song Name"
#but gives me: *notice no " 2080. Artist - Song Name"
#=>"HTTP/1.0 200 OK\r\nServer: Winamp httpQ Plugin Version
2.1\r\nContent-Type: text/html\r\n\r\n"

So I should receive the above string *plus* the return code, but ain't
getting the last. Any help is appreciated.

if it helps
Socket.getaddrinfo('localhost', 4800)#=>AF_INET, 4800, adartse,
127.0.0.1, 2, 2, 17

samples of code to use httpq, I'm looking at php's since I knew a
bit(and forgeting fast, thanks to ruby)
http://www.kostaa.com/winamp/sample.html

sorry for the long lines
*Adartse*
 
Ad

Advertisements

O

Osuka Adartse

Osuka said:
I have a question regarding sockets, I'm trying to use the HttpQ plugin
so open a socket to host x at 4800 plus passwd, and send commands, so
far so good(commands working), but I'm having trouble figuring how to
read the returned code.

All I keep getting is:"HTTP/1.0 200 OK\r\nServer: Winamp httpQ Plugin
Version 2.1\r\nContent-Type: text/html\r\n\r\n"
if I use Net::HTTP.new, I get the same so Net::HTTP.newobj is
at the end of this string there should be a return code like:

" 1" or " 5353. Singyguy - sillysong"

but there's nothing, so anybody have an idea how to do this?
Thanks emmanuel (why directly thought?) you put me on the right track
I should have used Net:HTTP like:

require "Net/http"
Net::HTTP.version_1_2
val=Net::HTTP.newobj("localhost","4800")
val.start
p val.get("/PLAY?p=passw")
#=>[#<Net::HTTPOK 200 readbody=true>, "1"]
#starts playing song

p val.get("/GETCURRENTTITLE?p=passwd")
#=>[#<Net::HTTPOK 200 readbody=true>, "2499. Carmina Burana - O Fortuna"]
#gets the song data

Now not only works, but also gives me the needed response!

And thanks to the stdlib project, help me quite a bit in http.rb:
Documented by Minero Aoki; converted to RDoc by William Webber. so
thanks Minero Aoki and Mr. Webber
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top