NAME

MojoX::NetstringStream - Turn a (tcp) stream into a NetstringStream

SYNOPSIS

use MojoX::NetstringStream;;

my $clientid = Mojo::IOLoop->client({
  port => $port,
} => sub {
  my ($loop, $err, $stream) = @_;
  my $ns = MojoX::NetstringStream->new(stream => $stream);
    $ns->on(chunk => sub {
       my ($ns, $chunk) = @_;
       say 'got chunk: ', $chunk;
       ...
    });
    $ns->on(close => sub {
       say 'got close';
       ...
    });
});

DESCRIPTION

MojoX::NetstringStream is a wrapper around Mojo::IOLoop::Stream that adds framing using the netstring encoding.

EVENTS

MojoX::NetstringStream inherits all events from Mojo::EventEmitter and can emit the following new ones.

chunk

$ns->on(chunk => sub {
  my ($ns, $chunk) = @_;
  ...
});

Emitted for every (full) netstring received on the underlying stream.

close

$ns->on(close => sub {
  my $ns = shift;
  ...
});

Emitted if the underlying stream gets closed.

ATTRIBUTES

MojoX::NetstringStream implements the following attributes.

stream

my $stream = $ns->stream;

The underlying Mojo::IOLoop::Stream-like stream

METHODS

MojoX::NetstringStream inherits all methods from Mojo::EventEmitter and implements the following new ones.

new

my $ns = MojoX::NetstringStream->new(stream => $stream);

Construct a new MojoX::NetstringStream object. The stream argument must behave like a Mojo::IOLoop::Stream object.

write

$ns->write($chunk);

Writes chunk to the underlying stream as a netstring.

SEE ALSO

Mojo::IOLoop, Mojo::IOLoop::Stream, http://mojolicious.org, https://cr.yp.to/proto/netstrings.txt.