我想为我的守护程序添加websocket支持,该守护程序已作为套接字服务器运行。我需要使用线程吗?
这是传入套接字连接的循环
while (not $signal)
{
# waiting for a new client connection
my $client_socket = $socket->accept();
# get information about a newly connected client
try {
my $client_address = $client_socket->peerhost();
my $client_port = $client_socket->peerport();
syslog("Connection from $client_address:$client_port");
# read up to 1024 characters from the connected client
my $data = "";
$client_socket->recv($data, 1024);
syslog("Received data: $data") if ($debug == 1);
# write response data to the connected client
my $resp_data = "ok";
$client_socket->send($resp_data);
# notify client that response has been sent
shutdown($client_socket, 1);
# parse command received
parse_cmd($data);
}
catch
{
syslog("Error receiving data");
}
}