HON Decentralized Justice - First Blockchain written in Perl6 - Stages: Talking to each other

3 months ago

We can now talk from node to node in a very preliminary way

So here we got a node listening on port 5000

#unit package EC::Network:auth<github:bioduds>;
unit module EC::Network;

class Socket {
  has IO::Socket::INET $.listener;
  method run {
    loop {
      my $conn = $!listener.accept;
      while my $buf = $conn.recv( :bin ) {
        say $buf;
        say $buf.decode( 'utf-8' );
        $conn.write: $buf;
        say "yo from listener";
      }
      $conn.close;
    }
  }
}

The caller

EC::Network::Socket.new(
  :listener( IO::Socket::INET.new(
    :listen, :localhost<192.168.1.106>, :localport(5000) ) ) ).run;

Then we fire up the node that is calling it

use v6;

loop {
  sleep-until now+2;
  my $conn = IO::Socket::INET.new(:host<192.168.1.106>, :port(5000));
  say "Client sending message...";
  $conn.print: 'Hello, Perl 6 here';
  say $conn.recv;
  $conn.close;
}

We run both, on client:

bioduds@BITWORKERS ~/bitworkers/EscrowChain/dev/client $ perl6 client.p6 
Client sending message...
Hello, Perl 6 here
Client sending message...
Hello, Perl 6 here
Client sending message...
Hello, Perl 6 here

On listener, we get:

bioduds@BITWORKERS ~/bitworkers/EscrowChain/dev $ perl6 test.p6 
Running Test...
Node receiving message (raw)
Buf[uint8]:0x<48 65 6c 6c 6f 2c 20 50 65 72 6c 20 36 20 68 65 72 65>
Node receiving message (decoded): Hello, Perl 6 here
Node receiving message (raw)
Buf[uint8]:0x<48 65 6c 6c 6f 2c 20 50 65 72 6c 20 36 20 68 65 72 65>
Node receiving message (decoded): Hello, Perl 6 here
Node receiving message (raw)
Buf[uint8]:0x<48 65 6c 6c 6f 2c 20 50 65 72 6c 20 36 20 68 65 72 65>

AWESOME! We have nodes talking to each other

Next issues now:

  • Begin a test net
  • Start traversal tests
  • Improve protocol

Cheers, don't forget to upvote, follow and resteem. It helps a lot


EDUARDO CAPANEMA
@bitworkers

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  trending

Followed 👏