#!/usr/bin/perl # ## *NOTE* this script is ran via terminal # # use strict; use warnings; use POE qw(Component::Server::TCP); # brian d foy's Modulino design pattern __PACKAGE__->poeServer(@ARGV) unless caller sub poeServer { POE::Component::Server::TCP->new( Started => sub { warn "Server started!\n"; }, Port => 8000, ClientConnected => sub { warn "Client connected!\n"; }, ClientDisconnected => sub { warn "Client disconnected!\n"; }, ClientInput => \&client_input, # because peer is SOCK_STREAM ClientFilter => "POE::Filter::Stream", Stopped => sub { warn "Server stopped!\n"; }, ); POE::Kernel->run(); exit; } sub client_input { my ($input) = $[ARG0]; warn "Client sent: $input\n"; my $reply = "00000"; # Acts as ACK to peer confirming data persisted $_[HEAP]{client}->put($reply); } sub ADD { my $handle = IO::Socket::INET->new( PeerHost => "XX.XX.XX.XX", # redacted PeerPort => 8001, Proto => "tcp", Type => SOCK_STREAM, ); my $message = "12345ABCD"; $handle->send($message); my $data; $handle->recv($data, 10); warn "Peer server responded with: $data\n"; $handle->close(); #### Need some way of being notified! }