JoeJaz has asked for the wisdom of the Perl Monks concerning the following question:
I want to be able to parse out those variables (which I am confident that I can do with some regular expressions), but I am not sure how to recieve this information in the first place. I want the script to wait for a web browser to send it the browser's header information, then parse the header information into variables, and finally send the browser back the html code and html header information (of which the last part it does now). I have played around with the IO::Socket's recv method a bit with no success. If anyone knows how to take in inforamtion in this way, I could greatly benifit from their experience. I appreciate your interest in this problem. Thanks for the read. Below is my code.GET /test.html HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/200 +30317 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/ +*;q=0.1 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate,compress;q=0.9 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Cookie: theme=Tabular Pragma: no-cache Cache-Control: no-cache
#!/usr/bin/perl -w use strict; use IO::Socket::INET; my $socket = IO::Socket::INET->new( LocalPort => 7788, Type => SOCK_STREAM, Reuse => 1, Listen => 10, ) or die "$!"; my ( $c, $content, $content_length, $server_type, $date, $text, $html_ +document, $header ); $text = &prepare_content; &serve; sub serve() { while ($c=$socket->accept()) { print $c "$text\n"; close($c); } close($socket); } sub prepare_content() { $html_document = $ARGV[0]; open(DOCUMENT, $html_document); my @content = <DOCUMENT>; close(DOCUMENT); $server_type = "Jazserv/1.0"; foreach my $temp (@content) { $content = $content . $temp; } $content_length = length($content); $date = `date`; print $content; $header = " HTTP/1.1 200 OK Server: $server_type ETag: \"\" Accept-Ranges: bytes Content-Length: $content_length Connection: close Content-Type: text/html; charset=ISO-8859-1 "; return "$header" . "$content"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: IO::Socket server
by merlyn (Sage) on Sep 08, 2003 at 02:21 UTC | |
by JoeJaz (Monk) on Sep 08, 2003 at 03:04 UTC | |
|
Re: IO::Socket server
by DigitalKitty (Parson) on Sep 08, 2003 at 02:57 UTC | |
by JoeJaz (Monk) on Sep 08, 2003 at 03:09 UTC |