Click to See Complete Forum and Search --> : Network question with Perl


eyceguy
02-12-2006, 02:37 PM
Ok, I'm having a problem with an MP3 Perl server that I ran into over at perlmonks.org

http://perlmonks.org/index.pl?node_id=8650

thing is I want to have a central server running this with stored playlists. and then the end user connects to it with an option as to what playlist they want.

Now what i want to do is connect to it from winamp/xmms/mpg123/whatever with an argument. for example

mpg123 http://127.0.0.1:8000?rock
or
mpg123 http://127.0.0.1:8000?plist=rock

I looked into CGI but it looks for the options on the command line when I run the server. How would I go about doing something like this? or better yet a direction to go to learn how to do this.

Now I know there are other programs around that do what im looking at and I know that i could run a seperate server on another port and have unique playlists for each, but I really would like to learn ho to do this, this way if at all possible. I looked through the perl cookbook and perl in a nutshell. Neither has a section that pertains to what I'm looking for. perlmonks.org has a crappy search tool (IMHO) and the only search phrases I can think for google give either no results or thousands of non-relevant results.

any help would be greatly appreciated.

eyceguy
02-13-2006, 12:54 PM
okay after looking around a little bit I think i better know what I want.

is there any way to retrieve the complete url a client uses to connect to a server.
for example if the client types in the url above is there a variable or function i can call that returns the WHOLE url. from there i think i can get the portion i want.

Also,
I jumped to another portion of my perl book dealing with LWP, i tried messing with it to see if i could get my results. Is this the right area to be looking in or am i going off on a tangent?

eyceguy
02-15-2006, 12:37 PM
okay so i've found out that LWP is for client side only. but im still trying to figure out how to obtain the full url a client uses to connect to a server.

any help? anyone?

bwkaz
02-15-2006, 08:32 PM
The client doesn't use a URL to connect to the server. The client uses a TCP connect() request; the only thing you can get from this is the target IP address and the destination port number. (Plus the source-IP and source-port, but those probably aren't any help.)

Anything more than this will depend entirely on the layer-7 protocol that you're using.

If you are using HTTP as your layer-7 protocol, then you can use the request-uri parameter (everything between the space after the GET, and the space before the HTTP/<version>), plus the Host: header (if provided), to build the full URL that the user-agent (browser/client/whatever) requested. If the user-agent only supports HTTP/0.9, then you probably won't get a Host: header, so you have to make do with whatever you get. (However, HTTP/0.9 clients seem to be very rare.)

If you're using a simple "connect, get data, disconnect" model, then there's no way, because you have no protocol above TCP.

I wonder if you're perhaps confusing socket-level servers with HTTP/CGI/whatever, or something?

eyceguy
02-16-2006, 05:19 PM
Okay so I understand what youre saying with the difference between a socket layer server and a HTTP server. In fact i've tried to switch the program from IO::Socket to HTTP::Daemon since the latter inherits from the first and when I dump the entire header this is what I get:

Connect to Server with Winamp with url: 127.0.0.1:8000?plist=rock

Output from server:
Server ready. Waiting for connections ...
Connecton recieved ... 127.0.0.1:8000
GET / HTTP/1.0
Connection: close
Accept: */*
Host: 127.0.0.1
User-Agent: WinampMPEG/5.11
Icy-MetaData: 1

As you can see the url I would get from the header is '/' which doesn't let me extract the 'plist=rock' from the url entered by the client.

eyceguy
02-16-2006, 05:25 PM
OMG OMG I GOT IT TO WORK!!

I was looking at my last post and just had a random idea. Instead of using the '?' like for a cgi program I decided what the H*** and try to use '/' and it worked! now the url to connect is
http://127.0.0.1:8000/plist=rock
instead of
http://127.0.0.1:8000?plist=rock

...and it works! Here is the header output:
Server ready. Waiting for connections ...
Connecton recieved ... 127.0.0.1:8000
GET /plist=rock HTTP/1.0
Connection: close
Accept: */*
Host: 127.0.0.1
User-Agent: WinampMPEG/5.11
Icy-MetaData: 1

Now I can extract the plist=rock, or if i wanted just leave off the 'plist='
I'll probably keep it, incase I decide to add other options later.

Thanks Bwkaz for the help you gave me. It at least help get me in the right direction.

Now its time to set up the mp3 server.