Skip to content
Netstring library for Perl 6
Perl 6
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Netstring library for Perl 6


Work with netstrings. This currently supports generating netstrings, and parsing a netstring from an IO::Socket (it would support further IO classes, except that the current Perl 6 implementations do not seem to have a more generic IO role.)


Generating Netstrings

  use Netstring;

  to-netstring("hello world!");
  ## returns "12:hello world!,"

  my $b =,0x65,0x6c,0x6c,0x6f,0x20,0x77,0x6f,0x72,0x6c,0x64,0x21);
  ## returns "12:hello world!,";

  to-netstring-buf("hello world!");
  ## returns Buf:0x<31 32 3a 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 2c>

  ## returns Buf:0x<31 32 3a 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 2c>

Reading Netstring from IO::Socket

  use Netstring;

  my $daemon =

  while my $client = $daemon.accept()
    ## The client sends "12:hello world!," as a stream of bytes.
    my $rawcontent = read-netstring($client);
    my $strcontent = $rawcontent.decode;

    say "The client said: $strcontent";
    ## prints "The client said: hello world!"

    ## sends "!dlrow olleh" back to the client.


Timothy Totten, supernovus on #perl6,


Artistic License 2.0

You can’t perform that action at this time.