Netstring library for Perl 6
Switch branches/tags
Nothing to show
Latest commit 2104c2e Oct 27, 2016 @supernovus committed on GitHub Merge pull request #5 from zoffixznet/patch-1
Add mandatory "perl" META field
Failed to load latest commit information.
lib Add unit declarator to module declarations May 27, 2015
t Fix removed @*INC Dec 5, 2015
.gitignore First commit. Oct 12, 2012
.travis.yml Add Travis configuration file Oct 23, 2015 Updated, the read-netstring() sub works on current Rakudo now. Mar 6, 2013

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