Net::EasyTCP

Net::EasyTCP is a Perl module that allows you to easily create secure, bandwidth-friendly TCP/IP clients and servers.
Download

Net::EasyTCP Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Mina Naguib
  • Publisher web site:
  • http://search.cpan.org/~mnaguib/EasyTCP-0.26/EasyTCP.pm

Net::EasyTCP Tags


Net::EasyTCP Description

Net::EasyTCP is a Perl module that allows you to easily create secure, bandwidth-friendly TCP/IP clients and servers. Net::EasyTCP is a Perl module that allows you to easily create secure, bandwidth-friendly TCP/IP clients and servers.Here are some key features of "Net EasyTCP":· One easy module to create both clients and servers· Object Oriented interface· Event-based callbacks in server mode· Internal protocol to take care of all the common transport problems· Transparent encryption· Transparent compressionSERVER EXAMPLE: use Net::EasyTCP; # # Create the server object # $server = new Net::EasyTCP( mode => "server", port => 2345, ) || die "ERROR CREATING SERVER: $@n"; # # Tell it about the callbacks to call # on known events # $server->setcallback( data => &gotdata, connect => &connected, disconnect => &disconnected, ) || die "ERROR SETTING CALLBACKS: $@n"; # # Start the server # $server->start() || die "ERROR STARTING SERVER: $@n"; # # This sub gets called when a client sends us data # 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 againn"; $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"; } } # # This sub gets called when a new client connects # sub connected { my $client = shift; my $serial = $client->serial(); print "Client $serial just connectedn"; } # # This sub gets called when an existing client disconnects # sub disconnected { my $client = shift; my $serial = $client->serial(); print "Client $serial just disconnectedn"; }CLIENT EXAMPLE: use Net::EasyTCP; # # Create a new client and connect to a server # $client = new Net::EasyTCP( mode => "client", host => 'localhost', port => 2345, ) || die "ERROR CREATING CLIENT: $@n"; # # Send and receive a simple string # $client->send("HELLO THERE") || die "ERROR SENDING: $@n"; $reply = $client->receive() || die "ERROR RECEIVING: $@n"; # # Send and receive complex objects/strings/arrays/hashes by reference # %hash = ("to be or" => "not to be" , "just another" => "perl hacker"); $client->send(%hash) || die "ERROR SENDING: $@n"; $reply = $client->receive() || die "ERROR RECEIVING: $@n"; foreach (keys %{$reply}) { print "Received key: $_ = $reply->{$_}n"; } # # Send and receive large binary data # for (1..8192) { for (0..255) { $largedata .= chr($_); } } $client->send($largedata) || die "ERROR SENDING: $@n"; $reply = $client->receive() || die "ERROR RECEIVING: $@n"; # # Cleanly disconnect from the server # $client->close();Requirements:· Perl


Net::EasyTCP Related Software