Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
45
Task/Distributed-programming/Perl/distributed-programming.pl
Normal file
45
Task/Distributed-programming/Perl/distributed-programming.pl
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use Data::Dumper;
|
||||
use IO::Socket::INET;
|
||||
use Safe;
|
||||
|
||||
sub get_data {
|
||||
my $sock = IO::Socket::INET->new(
|
||||
LocalHost => "localhost",
|
||||
LocalPort => "10000",
|
||||
Proto => "tcp",
|
||||
Listen => 1,
|
||||
Reuse => 1);
|
||||
unless ($sock) { die "Socket creation failure" }
|
||||
my $cli = $sock->accept();
|
||||
|
||||
# of course someone may be tempted to send you 'system("rm -rf /")',
|
||||
# to be safe(r), use Safe::
|
||||
my $safe = Safe->new;
|
||||
my $x = $safe->reval(join("", <$cli>));
|
||||
close $cli;
|
||||
close $sock;
|
||||
return $x;
|
||||
}
|
||||
|
||||
sub send_data {
|
||||
my $host = shift;
|
||||
my $data = shift;
|
||||
my $sock = IO::Socket::INET->new(
|
||||
PeerAddr => "$host:10000",
|
||||
Proto => "tcp",
|
||||
Reuse => 1);
|
||||
|
||||
unless ($sock) { die "Socket creation failure" }
|
||||
|
||||
print $sock Data::Dumper->Dump([$data]);
|
||||
close $sock;
|
||||
}
|
||||
|
||||
if (@ARGV) {
|
||||
my $x = get_data();
|
||||
print "Got data\n", Data::Dumper->Dump([$x]);
|
||||
} else {
|
||||
send_data('some_host', { a=>100, b=>[1 .. 10] });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue