I just wrote a function yesterday that uses IO::Socket to interact with an 
outside CGI program. It appears to work the way I want but this is my first 
foray into writing TCP client code.

It's basically this:

sub tcp_client {
     my ( $rhost, $rport, $query_string ) = @_;

     my $socket = IO::Socket::INET->new( PerrAddr => $rhost,
                                 PeerPort => $rport,
                                                 Proto    => "tcp",
                                                 Type     => SOCK_STREAM)
         or die "Couldn't connect to $rhost:$rport : $!\n";

     print $socket "GET /programname?$query_string\n";

     my $response;

     while ( <$socket> ) { $response .= $_ }

     close($socket);

     return \$answer;
}

--Jeff


At 06:58 AM 8/28/00 -0400, Steve Reppucci wrote:

>Just a word of warning: LWP::Simple doesn't follow redirects (at least,
>the last I checked, not sure if it's been changed in the 3 or 4
>months since I've last used it...), so you need to be certain that you're
>using it in a context where you're fetching something that won't return a
>redirect.
>
>HTH...
>
>On Sat, 26 Aug 2000, Stas Bekman wrote:
>
> > On Sat, 26 Aug 2000, Rodney Broom wrote:
> >
> > > OK, lots of banter...
> > >
> > > Hey V, if you are on a *NIX system, then this is a fast way:
> > >
> > > open U, "lynx -source www.some.url.dom |";
> > > $data = join '', <U>;
> > >
> > > There, you're finished. Admittedly, this isn't terribly efficiant, 
> but it works
> > > just fine and has short devel time.
> >
> > This one is much more efficient and requires even less coding:
> >
> > use LWP::Simple;
> > $content = get("http://www.sn.no/")
> >
> > And it doesn't require you to be on any particular OS, as far as I know.
> >
> > see perldoc LWP::Simple and as advised by many others LWP::UserAgent for
> > more advanced uses.
>
>
>=-=-=-=-=-=-=-=-=-=-  My God!  What have I done?  -=-=-=-=-=-=-=-=-=-=
>Steve Reppucci                                       [EMAIL PROTECTED] |
>Logical Choice Software                          http://logsoft.com/ |
>508/958-0183                                                 Be Open |

Jeff Beard
__________________________________
Web:            www.cyberxape.com
Email:  jeff at cyberxape dot com
Location:       Boulder, Colorado, USA

Reply via email to