Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Getting multiline input from a server

by HyperZonk (Friar)
on Jul 26, 2001 at 07:48 UTC ( [id://99886]=note: print w/replies, xml ) Need Help??


in reply to Getting multiline input from a server

If I'm not mistaken, it's because of your loop structure. Say that @from_server does indeed suck up all of the data from the socket (I am not convinced that it does, the suggested idiom is to loop across while defined($input = <$socket>)), then you get the number of lines slurped back as the scalar value of the assignment. It then loops and attempts to read from the socket again. Presumably, there is no more data on the socket, so it sits there and waits for data.

If assigning socket IO to an array works, and I would recommend using the suggested idiom instead, but if, you would want:
@from_server=<$socket>; print @from_server, "\n";
Note that there is no loop.

Update: As tilly noted, I am sure that it is your loop structure; what I'm not sure of is if it is hanging on the first pass because "you can't do that with sockets" or if it is because, "you can do that," but it is hanging on the second pass through the loop.

-HZ

Replies are listed 'Best First'.
Re: Re: Getting multiline input from a server
by nysus (Parson) on Jul 26, 2001 at 08:42 UTC
    Well I can yank that loop right out of there and I still get the same behavior. I found something interesting, however. I simplified the code to this:
    my (@from_server,$from_user); while (my $from_user = <>) { # a simple "GET" command print $socket $from_user; my @from_server = <$socket>; print @from_server; } close $socket;
    Now, this code works when connected to an HTTP port. This is what had me confused. I'm discovering the the bad behavior only occurs when connected to an FTP port where it will hang. Now is this because the connection is terminated by the server in an HTTP connection? I'm guessing this is what must be happening but I don't know for sure. When connected to an FTP, it waits and waits for more data to fill the array because the connection is still open, I'm also assuming.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://99886]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found