Distributed programming: Difference between revisions
m
→{{header|Wren}}: Minor tidy
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
m (→{{header|Wren}}: Minor tidy) |
||
(One intermediate revision by one other user not shown) | |||
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" }
Line 1,929 ⟶ 1,931:
<br>
We need two Wren scripts one for each VM:
<syntaxhighlight lang="
class Rpc {
Line 1,950 ⟶ 1,952:
HTTP.serve(listener)</syntaxhighlight>
<br>
<syntaxhighlight lang="
class TaxComputer {
Line 1,960 ⟶ 1,962:
<br>
We now embed these scripts in the following Go program and run it on one terminal.
<syntaxhighlight lang="go">/* go run
package main
Line 1,978 ⟶ 1,980:
var vm2 *wren.VM
var fileName = "
var fileName2 = "
func (taxRate TaxComputer) Tax(x float64, r *float64) error {
Line 2,049 ⟶ 2,051:
<br>
Just one Wren script needed here:
<syntaxhighlight lang="
import "./fmt" for Fmt
Line 2,067 ⟶ 2,069:
<br>
which we embed in the following Go program and run it on a different terminal.
<syntaxhighlight lang="go">/* go run
package main
Line 2,115 ⟶ 2,117:
cfg.LoadModuleFn = moduleFn
vm := cfg.NewVM()
fileName := "
clientMethodMap := wren.MethodMap { "call(_,_)": call }
classMap := wren.ClassMap { "Client": wren.NewClass(dialHTTP, nil, clientMethodMap) }
|