I have this interactice client:

#!/usr/bin/perl -w
use strict;
use IO::Socket;
my ($host, $port, $kidpid, $handle, $line);
unless (@ARGV == 2) { die "usage: $0 host port" }
($host, $port) = @ARGV;
# create a tcp connection to the specified host and port
$handle = IO::Socket::INET->new(Proto => "tcp",
PeerAddr => $host,
PeerPort => $port)
or die "can't connect to port $port on $host: $!";
$handle->autoflush(1); # so output gets there right away
print STDERR "[Connected to $host:$port]\n";
# split the program into two processes, identical twins
die "can't fork: $!" unless defined($kidpid = fork());
# the if{} block runs only in the parent process
if ($kidpid) { # copy the socket to standard output
while (defined ($line = <$handle>)) {
print STDOUT $line;
}
kill("TERM", $kidpid); # send SIGTERM to child
}
# the else{} block runs only in the child process
else { # copy standard input to the socket
while (defined ($line = <STDIN>)) {
print $handle $line;
}
}


on the server run this script:

#!perl -w

use IO::Socket;

$PORT = 7890;
$server = IO::Socket::INET-> new (LocalPort => $PORT,Listen => 5);

while ($client = $server->accept())
{
print $client "Command?\r\n";
$client->autoflush(1);
while ( <$client>)
{
if (/q/) { last; }
elsif (/dfc/) { print $client `dir /-C`."\r\n" ; }
print $client "Command?\r\n";
} close $client;
}




why don't work under WinXP? I have ASPerl 5.8. If I connect from telnet, client works normally. Thanks.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to