Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
Net::Analysis::ListeneUserxContributed PerNet::Analysis::Listener::Example1(3)

NAME
       Net::Analysis::Listener::Example1 - emit/receive	custom events

SYNOPSIS
	package	Net::Analysis::Listener::Example1;

	use strict;
	use warnings;
	use base qw(Net::Analysis::Listener::Base);

	sub tcp_monologue {
	    my ($self, $args) =	@_;
	    my ($mono) = $args->{monologue}; # isa Net::Analysis::TCPMonologue

	    my $t = $mono->t_elapsed()->as_number();
	    my $l = $mono->length();

	    $self->emit(name =>	'example_bandwidth_measurement_event',
			args =>	{ kb_sec => ($t) ? $l/($t*1024)	: 0 }
		       );
	}

	sub example_bandwidth_measurement_event	{
	    my ($self, $args) =	@_;

	    printf "Bandwidth: %10.2f KB/sec\n", $args->{kb_sec};
	}

	1;

       You can invoke this example on a	TCP capture file from the command
       line, as	follows:

	$ perl -MNet::Analysis -e main Example1	t/t1_google.tcp

DESCRIPTION
       This example shows how to emit your own custom events, and also how to
       listen to them. This particular example has
       "example_bandwidth_measurement_event" in	the same Listener.pm file, but
       you could easily	put it in another Listener.pm if you wanted - just
       remember	to tell	the dispatcher about both of them.

SEE ALSO
       Net::Analysis.

AUTHOR
       Adam B. Worrall,	<worrall@cpan.org>

COPYRIGHT AND LICENSE
       Copyright (C) 2004 by Adam B. Worrall

       This library is free software; you can redistribute it and/or modify it
       under the same terms as Perl itself, either Perl	version	5.8.5 or, at
       your option, any	later version of Perl 5	you may	have available.

perl v5.32.1			  2010-03-Net::Analysis::Listener::Example1(3)

NAME | SYNOPSIS | DESCRIPTION | SEE ALSO | AUTHOR | COPYRIGHT AND LICENSE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Net::Analysis::Listener::Example1&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help