【发布时间】:2017-09-27 17:08:30
【问题描述】:
我正在编写一个 perl 服务器,它使用公钥和私钥对客户端进行身份验证,最终我需要 $client_socket->recv 是事件驱动的,而不是无限循环的轮询。是否有内置代码来执行由 IO::Socket::INET 驱动的事件。
while(1)
{
# waiting for a new client connection
my $client_socket = $socket->accept();
# get information about a newly connected client
my $client_address = $client_socket->peerhost();
my $client_port = $client_socket->peerport();
print "connection from $client_address:$client_port\n";
# read up to 1024 characters from the connected client
my $data = "";
$client_socket->recv($data, 1024);
print "received data: $data\n";
# write response data to the connected client
$client_socket->send("some response text");
# notify client that response has been sent
shutdown($client_socket, 1);
}
【问题讨论】:
标签: perl