我的客户.pl
#!/usr/bin/perl
use IO::Socket::INET;
use strict;
my $name = '172.20.10.189'; #Server IP
my $port = '7890';
my $socket = IO::Socket::INET->new('PeerAddr' => $name,
'PeerPort' => $port,
'Proto' => 'tcp') or die "Can't create socket ($!)\n";
print "Client sending\n";
while (1) {
my $msg = <STDIN>;
print $socket $msg;
print scalar <$socket>;
}
close $socket
or die "Can't close socket ($!)\n";
我的服务器.pl
#!/usr/bin/perl
use IO::Socket::INET;
use strict;
my $port = "7890";
my $socket = IO::Socket::INET->new('LocalPort' => $port,
'Proto' => 'tcp',
'Listen' => SOMAXCONN)
or die "Can't create socket ($!)\n";
while (my $client = $socket->accept) {
my $name = gethostbyaddr($client->peeraddr, AF_INET);
my $port = $client->peerport;
while (<$client>) {
print "[$name $port] $_";
my @out = `$_`;
print @out;
print $client "$.: @out";
}
close $client
or die "Can't close ($!)\n";
}
die "Can't accept socket ($!)\n";
我的客户端正在向服务器发送命令(ls -lrt /),服务器应该运行该命令并将输出发送回客户端。
问题:-
该命令在服务器上成功执行,但它只向客户端发送第一行。如果我再次按下客户端的任何键,则下一行输出将发送到客户端。
或者告诉我如何将多行输出发送回客户端。
任何帮助,将不胜感激。
谢谢阿布舍克