我有这段代码:
#!/usr/bin/perl
use strict;
use warnings;
use FCGI;
my $socket = FCGI::OpenSocket(":9000", 5);
my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, $socket);
my $count = 1;
while($request->Accept() >= 0) {
print "Content-Type: text/html; charset=UTF-8\r\n\r\n";
print $count++, "<br />";
}
我需要在接受后创建客户端套接字。我怎么能这样做?
答案 0 :(得分:0)
我解决了这个问题。
#!/usr/bin/perl
use strict;
use warnings;
use FCGI;
use Socket;
my $socket = FCGI::OpenSocket(":9000", 5);
my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, $socket);
my $count = 1;
while($request->Accept() >= 0) {
print "Content-Type: text/html; charset=UTF-8\r\n\r\n";
print $count++, "<br />";
print "$$<br />";
open(my $client, "+>&4") or die "$!";
my $mysockaddr = getsockname($client) or die "$!";
my ($myport, $myaddr) = sockaddr_in($mysockaddr);
print $myport, ":", inet_ntoa($myaddr), "<br />";
my $peersockaddr = getpeername($client) or die "$!";
my ($peerport, $peeraddr) = sockaddr_in($peersockaddr);
print $peerport, ":", inet_ntoa($peeraddr), "<br />";
close $client;
}