[Chicago-talk] TCP server.

Greg Fast gdf at speakeasy.net
Sat Jul 16 18:33:50 PDT 2005


On Sat, Jul 16, 2005 at 05:57:36AM -0700, Richard Reina wrote:
> >     # ...
> >     accept( $client, $server_sock );
> >     open( my $in, "/bin/date |" ) || die $!;
> >     while( <$in> ) {
> >       print {$client_sock} $_;
> >     }
> 
> Thank you very much for your response.  Would the
> lines of code above be something that that the program
> outside the TCP server uses?   

No, that's code for inside the server.  I used the old syscall-style
accept() call, with IO::Socket that'd be
$client_sock=$server_sock->accept()  (I also misspelled $client_sock,
oops...)

In the client, you should be able to just read and write to the
socket, just like in the server.  Something like:

    my $s = IO::Socket::INET->new(
      PeerAddr => "www.google.com:80",
      Proto => "tcp",
    ) || die "Can't connect ($!)";
    
    print {$s} "HEAD / HTTP/1.0\r\n\r\n";
    while (<$s>) {
      print $_;
    }

Is that what you're looking for?

-- 
Greg Fast
gdf at speakeasy.net
http://cken.chi.groogroo.com/


More information about the Chicago-talk mailing list