我正在编写一个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);
}发布于 2017-09-28 01:11:21
编号:
Perl没有内置任何用于事件驱动编程的东西。在CPAN上可以使用各种模块进行事件驱动开发。其中一些在Task::Kensho::Async中列出。
https://stackoverflow.com/questions/46453561
复制相似问题