Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

I'd like to do the following:

Take user input via a client (string and numerical). Transmit this information to a server (UNIX server, which must be supplied with an ID and password). Provide User Input to 1 perl Script. Run that script, and following it's completion, run several other scripts until we end up with a file. This file is to be returned to the client, which can handle it's presentation from there.

Any good ways to do this in Perl? Advice on how to handle packets for log on and password is appreciated.

Thanks very much!

Replies are listed 'Best First'.
Re: Client-Server Communication
by pc88mxer (Vicar) on May 27, 2008 at 16:36 UTC
    Sounds like you could just use ssh for this. In fact, you might not have to write any perl at all.
Re: Client-Server Communication
by moritz (Cardinal) on May 27, 2008 at 16:32 UTC
    Which protocols do you want to use for which task?
Re: Client-Server Communication
by Anonymous Monk on May 27, 2008 at 20:26 UTC
    Do you really think it's a good idea posting my homework assignments? The class is not so big. I will soon know who you are.
Re: Client-Server Communication
by apl (Monsignor) on May 27, 2008 at 16:41 UTC
Re: Client-Server Communication
by zentara (Cardinal) on May 27, 2008 at 19:39 UTC
    For easy logon and password, use Net::EasyTCP. I have a few examples floating around, for example Sockets-File-Upload with Net::EasyTCP

    You can easily adapt this to your purposes. Also read the latest docs for Net::EasyTCP, for it has improved since I wrote the above example. Below is a super simple example. Start the server first, and afterwards start the client. Be patient, and wait for the client to establish the encryption. If it uses RSA, it can take about 5 seconds for the first transfer to occur( makes and transfers keys).... then it works fast. You can force it to use faster (or no encryption). Read the docs.

    #server #!/usr/bin/perl use warnings; use strict; use Net::EasyTCP; #my @nocrypt = qw(Crypt::RSA); #too slow, but more secure #my @nocompress = qw(Compress::LZF); #just testing this feature my $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"; print "server started\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"; }
    # client #!/usr/bin/perl use Net::EasyTCP; $client = new Net::EasyTCP( mode => "client", host => 'localhost', port => 2345, password => ztest ) || die "ERROR CREATING CLIENT: $@\n"; my $encrypt = $client->encryption(); my $compress = $client->compression(); print "encryption method ->$encrypt\ncompression method ->$compress\n" +; my $encryption = $client->encryption() || "NO"; my $compression = $client->compression() || "NO"; print "Using $encryption encryption and $compression compression\n\n"; #Send and receive a simple string $client->send("HELLO THERE") || die "ERROR SENDING: $@\n"; $reply = $client->receive() || die "ERROR RECEIVING: $@\n"; print "$reply\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..4096) { #for (0..255) { #$largedata .= chr($_); #} #} #$client->send($largedata) || die "ERROR SENDING: $@\n"; #$reply = $client->receive() || die "ERROR RECEIVING: $@\n"; #$client->close(); $client->send('Hello from Joe') || die "ERROR SENDING: $@\n"; $reply = $client->receive() || die "ERROR RECEIVING: $@\n"; print "$reply\n"; while(1){ $input = <STDIN>; $client->send($input) || die "ERROR SENDING: $@\n"; $reply = $client->receive() || die "ERROR RECEIVING: $@\n"; print "$reply\n"; }

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum