Very quickly - the Perl Cookbook has a number of working examples in Chapter
17

 

Just in

 

From: perl-win32-users-boun...@listserv.activestate.com
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Greg
Aiken
Sent: Wednesday, 22 April 2009 7:36 AM
To: perl-win32-users@listserv.activestate.com
Subject: IO::Socket question (client receive - when # of bytes to be
received is NOT known in advance)

 

method 1 (below) does work to receive a response from a server.  but
requires I know in advance the number of bytes to receive.

 

I am wondering if something like method 2 may be used in the case of where
one does NOT know in advance how many bytes the server will be sending.  ive
attempted to try this using the code presented in method 2, but this fails
miserably.  was hoping someone in the group had a working alternative method
to share.

 

 

use IO::Socket;

 

$http_get_request = << "HTTP_GET";

GET /index.htm HTTP/1.1

Host: google.com

Keep-Alive: timeout=15, max=60

Connection: keep-alive

 

HTTP_GET

 

#setup client socket

$main::socket = new IO::Socket::INET 

( Proto  => "tcp", PeerAddr => "google.com", PeerPort => "80", );

$main::socket->autoflush(1);

 

#send http1.1 (persistent connection) request for data

$main::socket->send($http_get_request);

 

 

#receive the http1.1 response...

 

#method 1

#this method works

#but requires i know how many bytes to receive

#which I dont always know - so i dont like this method

            $main::socket->recv($response, 8192);

            print $response;

 

#method 2

#cant something like this be done instead?

#i would prefer to use this pseudo-code method

#as there is no hard-coded number of bytes to receive

#is there a way to achieve this?

#          while ( $main::socket->recv($block, 8192) ) {

#             $response .= $block;

#          }

#          print $response;

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to