Hello world/Web server: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl}}: changed message to HTML and added HTTP status code)
(→‎{{header|Perl}}: added simpler solution using an extra module)
Line 136: Line 136:
}</lang>
}</lang>


Various modules exist for using sockets, including the popular IO::Socket which provides a simpler and more friendly OO interface for the socket layer. I refrained from using this module in order to use only what is provided by the average default Perl installation.
Various modules exist for using sockets, including the popular IO::Socket which provides a simpler and more friendly OO interface for the socket layer. Here is the solution using this module:

{{libheader|IO::Socket::INET}}

<lang Perl>use IO::Socket::INET;

my $sock = new IO::Socket::INET ( LocalHost => "127.0.0.1",
LocalPort => "8080",
Proto => "tcp",
Listen => 1,
Reuse => 1, ) or die "Could not create socket: $!";

while( my $client = $sock->accept() ){
print $client "HTTP/1.1 200 OK\r\n" .
"Content-Type: text/html; charset=UTF-8\r\n\r\n" .
"<html><head><title>Goodbye, world!</title></head><body>Goodbye, world!</body></html>\r\n";
close $client;
}</lang>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==