Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Reading a returned code from socket and httpq

Reply
Thread Tools

Reading a returned code from socket and httpq

 
 
Osuka Adartse
Guest
Posts: n/a
 
      11-30-2003
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(12.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(12.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*



 
Reply With Quote
 
 
 
 
Osuka Adartse
Guest
Posts: n/a
 
      12-01-2003
Osuka Adartse wrote:

> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Incorrect number of bytes returned by getsockopt(socket.SOL_SOCKET,socket.TCP_INFO, buflen) Ashwin Rao Python 2 12-03-2009 09:36 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments