【发布时间】:2016-05-27 15:21:05
【问题描述】:
这里是请求网址http://localhost:9009/?comd&user=kkc&mail=kkc@kkc.com
服务器perl脚本需要做哪些修改。
服务器-Perl-脚本
use IO::Socket;
use Net::hostent; # for OO version of gethostbyaddr
$PORT = 9009; # pick something not in use
$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $PORT,
Listen => SOMAXCONN,
Reuse => 1);
die "can't setup server" unless $server;
print "[Server $0 accepting clients]\n";
while ($client = $server->accept())
{
$client->autoflush(1);
print $client "Welcome to $0; type help for command list.\n";
$hostinfo = gethostbyaddr($client->peeraddr);
printf "[Connect from %s]\n", $hostinfo ? $hostinfo->name : $client->peerhost;
print $client "Command? ";
while ( <$client>) {
next unless /\S/; # blank line
if (/comd/i ) { print $client `dir`; }
} continue {
print $client "Command? ";
}
close $client;
print "client closed";
}
【问题讨论】:
-
首先使用 HTTP 服务器而不是原始套接字。
-
These answers 可能展示了在 Perl 中构建 HTTP 服务器的更好方法。
标签: perl