0

我有这个代码:

#!/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 />";

}

我需要在接受后创建客户端套接字。我怎么能那样做?

4

1 回答 1

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;
}
于 2013-06-30T17:52:57.503 回答