2013-06-28 62 views
0

我有這樣的代碼來獲得一個客戶端套接字:我想用FCGI.pm

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

你想用該代碼實現什麼? 'FCGI'似乎是一個奇怪的模塊使用。 – innaM

回答

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; 
} 
+0

您可以接受您自己的答案,將此問題標記爲已解決。 – nemo