Reading a returned code from socket and httpq

Discussion in 'Ruby' started by Osuka Adartse, Nov 30, 2003.

  1. 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*
     
    Osuka Adartse, Nov 30, 2003
    #1
    1. Advertising

  2. 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
     
    Osuka Adartse, Dec 1, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laszlo Nagy
    Replies:
    1
    Views:
    4,874
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    979
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    558
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    674
    Steve Holden
    Feb 1, 2009
  5. Ashwin Rao
    Replies:
    2
    Views:
    1,057
    Martien Verbruggen
    Dec 3, 2009
Loading...

Share This Page