Distributed programming: Difference between revisions
m
→{{header|Perl}}: future-proof for 5.36
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: future-proof for 5.36) |
||
Line 1,150:
=={{header|Perl}}==
Using Data::Dumper and Safe to transmit arbitrary data structures as serialized text between hosts. Same code works as both sender and receiver.
<syntaxhighlight lang="perl">use
use warnings;
use Data::Dumper;
use IO::Socket::INET;
use Safe;
sub get_data {
my $sock =
LocalHost => "localhost",
LocalPort => "10000",
Proto => "tcp",
Listen => 1,
Reuse => 1);
unless ($sock) { die "Socket creation failure" }
my $cli = $sock->accept();
Line 1,166 ⟶ 1,168:
# of course someone may be tempted to send you 'system("rm -rf /")',
# to be safe(r), use Safe::
my $safe =
my $x = $safe->reval(join("", <$cli>));
close $cli;
Line 1,176 ⟶ 1,178:
my $host = shift;
my $data = shift;
my $sock =
PeerAddr => "$host:10000",
Proto => "tcp",
Reuse => 1);
unless ($sock) { die "Socket creation failure" }
|