Qitan has asked for the wisdom of the Perl Monks concerning the following question:

I have a program that I am trying to get working on my system. The program uses a GUI that is accessed thru http://localhost:8080. I cannot get my browser to connect to that address. I've done some rudimentary debugging using print statements to see where in the prog things go awry. Here is a snippet of the program where things go wrong.
# See if there's a connection waiting on the $server by getting the l +ist of handles with data to # read, if the handle is the server then we're off. Note the +0.1 second delay here when waiting # around. This means that we don't hog the processor while wa +iting for connections. my ($ready) = $selector->can_read(0.1); my ($uiready) = $uiselector->can_read(0.1); # Handle HTTP requests for the UI if ( $uiready == $ui ) { if ( my $client = $ui->accept() ) { # Check that this is a connection from the local machi +ne, if it's not then we drop it immediately # without any further processing. We don't want to al +low remote users to admin my ( $remote_port, $remote_host ) = sockaddr_in( $clie +nt->peername() ); if ( $remote_host eq inet_aton( "127.0.0.1" ) ) { if ( my $request = <$client> ) { debug( $request ); while ( <$client> ) { if ( !/(.*): (.*)/ ) { last; } } if ( $request =~ /GET (.*) HTTP\/1\./ ) { my $url = $1; print $client handle_url($url); } else { print $client http_error(500); } } } close $client;
The line: if ( my $request = <$client> ) is what fails and it jumps down to the 'close $client;' line. My knowledge of Perl is not great but from what I know, <$client> is trying to read a line of data from the socket that was setup. If I print the value of $client I get: IO::Socket::INET=GLOB(0x1b4dfd8) When I try to print the value of <$client> I get no response from the program. I am running WinXP Home sp1, Internet Explorer 6 sp1 and the perl that I'm using is Activestate 5.6.1. Any ideas? Thanks

Replies are listed 'Best First'.
Re: Problem reading the value of <$client>
by chromatic (Archbishop) on Dec 02, 2002 at 22:46 UTC

    You might find HTTP::Daemon easier to use.

    No errors leap out at me. Try telnet localhost 8080 and type a few lines. If you see it, there's a client problem.

    On second thought, did you redefine $/ anywhere?

      I've tried using telnet. It seems to connect fine but as soon as I type a character, I lose connection to the host. Like I said my knowledge of Perl is minimal, but shouldn't I be able to 'print <$client>' to see what the value of <$client> is. At this point in the code, the server is waiting for a command from the browser. I am assuming that <$client> should be the GET command from the browser.
Re: Problem reading the value of <$client>
by traveler (Parson) on Dec 02, 2002 at 23:41 UTC
    I cannot see where you set up $ui. Presumably it is with $IO::Socket::INET->new(). At any rate, I'd try a print of the inet_ntoa($remote_host) just after the my just in case your debuggery is incorrect. I say that because the close appears to be after the if and inside, not after, the while.

    Update: You might want to send the client a message before the close, too. Also, $client->autoflush(1); is probably a good idea, too.

    HTH, --traveler

Re: Problem reading the value of <$client>
by dingus (Friar) on Dec 03, 2002 at 10:03 UTC
    I think I recognise that code - its popfile or something derived from it. You might try contacting the popfile developer(s) if you are trying to use popfile itself.

    What you should probably do if you want to debug it yourself is break the line into two and do the debugging in the middle:

    my $request = <$client>; # debug line print "Degbug: $request\n"; # end of debug line if ( $request ) { ...

    Dingus


    Enter any 47-digit prime number to continue.