#!/usr/bin/perl
use IO::Socket;
my $dest = shift;
my $port = shift;
my $message;
my $line;
my $sock = IO::Socket::INET -> new ( PeerAddr => $dest, PeerPort => $port, Proto => "tcp" ) or die "Could not establish TCP connection: $!";
$sock->autoflush(1);
while (1)
{
$message = <stdin>;
print $sock $message;
while ($line = <$sock>)
{
print $line;
}
}
close $sock;
petrichor (/'pe - tri - kor'/) is the familiar scent of rain on dry earth
this tech blog is the wafting fragrance of my geeky outpourings, one post at a time
Wednesday, April 16, 2008
perl: simple socket programming
Here's a telnet kinda program in perl (i.e. a generic TCP client):
Labels:
networking,
perl,
programming
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment