echo server
programming/perl 2010. 11. 29. 19:26 |use IO::Socket;
sub connection {
my ($a_sock) = @_;
print $a_sock " *** TCP ECHO SRV ***\n\n\r";
while( defined($buf = <$a_sock>)) {
print $a_sock $buf;
}
exit;
}
my $sock = new IO::Socket::INET (LocalHost => 'ANY',
LocalPort => 4242,
Proto => 'tcp',
Listen => 5,
Reuse => 1);
die "Unable to create Socket, error: $!" unless $sock;
print "Tcp server running\n";
sub REAPER {
while(waitpid(-1,WNOHANG) > 0) { ; }
$SIG{CHLD} = \&REAPER;
}
$SIG{CHLD} = \&REAPER;
my $a_sock;
while (1) {
$a_sock = $sock->accept();
if (defined($a_sock)) {
my $pid = fork;
if ($pid == 0) {
connection($a_sock);
exit(0);
} else {
close($a_sock);
}
}
}
close $sock;
'programming > perl' 카테고리의 다른 글
socket TCP server (0) | 2010.05.10 |
---|---|
udp request (0) | 2010.05.10 |
tcp request (0) | 2010.05.10 |
외부파일실행예제 (0) | 2010.04.28 |
웹페이지 긁어오기 예제 (0) | 2010.04.09 |