Test::POE::Client::TCP

Test::POE::Client::TCP is a POE component that provides TCP client services for test cases.
Download

Test::POE::Client::TCP Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Chris Williams
  • Publisher web site:
  • http://search.cpan.org/~bingos/

Test::POE::Client::TCP Tags


Test::POE::Client::TCP Description

Test::POE::Client::TCP is a POE component that provides TCP client services for test cases. Test::POE::Client::TCP is a POE component that provides TCP client services for test cases.SYNOPSIS use strict; use Socket; use Test::More tests => 15; use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line); use Test::POE::Client::TCP; my @data = ( 'This is a test', 'This is another test', 'This is the last test', ); POE::Session->create( package_states => , ], heap => { data => @data, }, ); $poe_kernel->run(); exit 0; sub _start { my ($kernel,$heap) = @_; $heap->{listener} = POE::Wheel::SocketFactory->new( BindAddress => '127.0.0.1', SuccessEvent => '_accept', FailureEvent => '_failed', SocketDomain => AF_INET, # Sets the socket() domain SocketType => SOCK_STREAM, # Sets the socket() type SocketProtocol => 'tcp', # Sets the socket() protocol Reuse => 'on', # Lets the port be reused ); $heap->{testc} = Test::POE::Client::TCP->spawn(); return; } sub _accept { my ($kernel,$heap,$socket) = @_; my $wheel = POE::Wheel::ReadWrite->new( Handle => $socket, InputEvent => '_sock_in', ErrorEvent => '_sock_err', ); $heap->{wheels}->{ $wheel->ID } = $wheel; return; } sub _failed { my ($kernel,$heap,$operation,$errnum,$errstr,$wheel_id) = @_; die "Wheel $wheel_id generated $operation error $errnum: $errstrn"; return; } sub _sock_in { my ($heap,$input,$wheel_id) = @_; pass('Got input from client'); $heap->{wheels}->{ $wheel_id }->put( $input ) if $heap->{wheels}->{ $wheel_id }; return; } sub _sock_err { my ($heap,$wheel_id) = @_; pass('Client disconnected'); delete $heap->{wheels}->{ $wheel_id }; return; } sub testc_registered { my ($kernel,$sender,$object) = @_; pass($_); my $port = ( sockaddr_in( $_->{listener}->getsockname() ) ); $kernel->post( $sender, 'connect', { address => '127.0.0.1', port => $port } ); return; } sub testc_connected { my ($kernel,$heap,$sender) = @_; pass($_); $kernel->post( $sender, 'send_to_server', $heap->{data}-> ); return; } sub testc_flushed { pass($_); return; } sub testc_input { my ($heap,$input) = @_; pass('Got something back from the server'); my $data = shift @{ $heap->{data} }; ok( $input eq $data, "Data matched: '$input'" ); unless ( scalar @{ $heap->{data} } ) { $heap->{testc}->terminate(); return; } $poe_kernel->post( $_, 'send_to_server', $heap->{data}-> ); return; } sub testc_disconnected { my ($heap,$state) = @_; pass($state); delete $heap->{wheels}; delete $heap->{listener}; $heap->{testc}->shutdown(); return; } Requirements: · Perl


Test::POE::Client::TCP Related Software