#! /usr/bin/perl use warnings; use strict; use threads; use threads::shared; use IO::Socket::INET; use IO::Select; use POSIX; use constant SERVERPORT => 8090; use constant CRLF => "\015\012"; use vars qw($Done); $Done = 0; $| = 1; my $socket = IO::Socket::INET->new ( LocalPort => SERVERPORT, Listen => SOMAXCONN, Reuse => 1, ) or die "Error: couldn't create listening socket: $!\n"; my $in = IO::Select->new($socket); print "Listening for connections on port: ", SERVERPORT, "...\n"; while (! $Done) { next unless $in->can_read(); next unless my $conn = $socket->accept; threads->new(\&HandleConnection, $conn); } # while warn "Normal termination\n"; # ======================================================= sub HandleConnection { my $conn = shift; my $thread = threads->self; $conn->send(""); $conn->send("

Testpage

"); $conn->send(""); $conn->close(); print "Connection: ", $thread->tid, " finished------\n"; } # HandleConnection