blob: 3fe3035387d707d1bbc5c82516f3ac629777725e (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#!/usr/bin/perl
use POSIX;
use IO::Socket;
if ( scalar(@ARGV) < 2 ){
print( "Usage: ".__FILE__." [IP] [port]\n" );
exit( 0 );
}
my $resp = "HTTP/1.1 200 OK\r\nServer: perlhttp\r\nContent-Type: text/html\r\n\r\n<html><body><center><h1>Hi there</h1></body></html>";
my $ssock = IO::Socket->new(
"LocalHost" => $ARGV[0],
"LocalPort" => $ARGV[1],
"Listen" => 10,
"Blocking" => 1,
"Type" => IO::Socket::SOCK_STREAM,
"Domain" => IO::Socket::AF_INET,
"Proto" => "tcp",
"ReusePort" => 1,
"ReuseAddr" => 1
) or die "Failed to create socket";
my $req = "";
my $psock = "";
print( "Listening on http://".$ARGV[0].":".$ARGV[1]."\n" );
while ( $psock = $ssock->accept() ){
print( "Request from ".$psock->peerhost()."\n" );
$psock->recv( $req, 524288 );
$psock->send( $resp );
$psock->shutdown( SHUT_RDWR );
$req = "";
}
undef $req;
undef $ssock;
undef $psock;
exit( 0 );
|