#server #!/usr/bin/perl use Net::EasyTCP; #my @nocrypt = qw(Crypt::RSA); #too slow, but more secure #my @nocompress = qw(Compress::LZF); #just testing this feature $server = new Net::EasyTCP( host => "localhost", mode => "server", port => 2345, password => "ztest", donotcheckversion => 1, # donotencryptwith => \@nocrypt, # donotencrypt => 1, # donotcompresswith => \@nocompress, # donotcompress => 1, welcome => "Hi! Wecome to the test server!\n", ) || die "ERROR CREATING SERVER: $@\n"; $server->setcallback( data => \&gotdata, connect => \&connected, disconnect => \&disconnected, ) || die "ERROR SETTING CALLBACKS: $@\n"; $server->start() || die "ERROR STARTING SERVER: $@\n"; #################################################### sub gotdata() { my $client = shift; my $serial = $client->serial(); my $data = $client->data(); print "Client $serial sent me some data, sending it right back to them again\n"; $client->send($data) || die "ERROR SENDING TO CLIENT: $@\n"; if ($data eq "QUIT") { $client->close() || die "ERROR CLOSING CLIENT: $@\n"; } elsif ($data eq "DIE") { $server->stop() || die "ERROR STOPPING SERVER: $@\n"; } } ##################################################### sub connected() { my $client = shift; my $serial = $client->serial(); print "Client $serial just connected\n"; } ################################################### sub disconnected() { my $client = shift; my $serial = $client->serial(); print "Client $serial just disconnected\n"; }