I'm working on a small test server that displays "hello world" on both the server screen and the client screen. my problem is when i disconnect the client "ctrl-c" the server doesn't know this. how do i detect that the client has disconnected so the server can reset itself and wait for a new connection?
Code:
#!/usr/bin/perl -w
use IO::Socket;
$PORT = 3334;
$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $PORT,
Listen => SOMAXCONN,
Reuse => 1)
or die "can't setup server" unless $server;
print $server->sockport."\n";
while (my $client = $server->accept()) {
$client->autoflush(1);
while ($client) {
$outstream = "Hello World";
print $outstream ."\r\n";
print $client $outstream ."\r\n";
sleep 1;
}
$client->close;
}
$server->close;