#!/usr/bin/perl
use IO::Socket; #by Cypher
my $so = new IO::Socket::INET(LocalPort => '5446',
                                 Proto => 'tcp',
                                Listen => 1,
                                 Reuse => 1,); #define a new socket for use
 
die "Socket Error: $!\n" unless $so; #check whether socket is working

print "Server started...\n";

while ($client = $so->accept()) { #accept connection
	while( defined( $msg = <$client> ) ) { #recieve message from client
		chomp($msg);
		@a = split(" ", $msg);
		($cmd, $arg) = @a; #split message into command and argument.
		
		#now analyze the command
		if ($cmd eq "hello") { print "Client connected\n" }
		elsif ($cmd eq "kill") { exit 1;}
		elsif ($cmd eq "delete") { unlink($arg) }
		else { print "$msg\n" }
}
}
close ($client, $so); #close connection