<html><body><pre> #!/usr/bin/perl -w # el cliente ($them,$port) = @ARGV; $port = 2348 unless $port; $them = 'scfie.eie.umich.mx' unless $them; #localhost' unless $them; $SIG{'INT'} = 'dokill'; sub dokill { kill 9,$child if $child; } use Socket; $sockaddr = 'S n a4 x8'; chop($hostname = `hostname`); ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; ($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname); ($name, $aliases, $type, $len, $thataddr) = gethostbyname($them); $this = pack($sockaddr, &AF_INET, 0, $thisaddr); $that = pack($sockaddr, &AF_INET, $port, $thataddr); print "Esta direccion: $thisaddr\n"; print "En cliente, conectar a: $them por el puerto: $port\n"; socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!"; bind(S, $this) || die "bind: $!"; connect(S, $that) || die "connect: $!"; select(S); $| = 1; select(STDOUT); if ($child = fork) { while (<STDIN>) { print S; } sleep 3; #do dokill(); } else { while (<S>) { print; } } close(S) || die "close: $!"; exit; </pre></body></html>