use strict; use warnings; use Tk; # This MUST come before use POE... use POE; use POE::Component::Client::TCP; use Data::Dumper; # This connects to the ssh port on the local machine (modify as required)... my $host = 'localhost'; my $port = '22'; my $textw; # Global for text widget _processData(); _displayData(); print STDERR "STARTING to process data...\n"; POE::Kernel->run; exit; sub _processData{ POE::Component::Client::TCP->new( RemoteAddress => $host, RemotePort => $port, Filter => "POE::Filter::Line", Alias => 'myClient', Connected => sub { $textw->insert(end=>"connected to $host:$port ...\n"); $textw->update; }, ConnectError => sub { $textw->insert(end=>"no connection to $host:$port. Reconnecting in 5...\n"); $textw->update; $_[KERNEL]->delay( reconnect =>5 ); }, ServerInput => sub { my $input = $_[ARG0]; $_[KERNEL]->post(Display=>data=>$input); }, ); } sub _displayData{ POE::Session->create( inline_states => { _start => sub { my $kern = $_[KERNEL]; $kern->alias_set("Display"); my $top = $poe_main_window; my $sess=$kern->alias_resolve('myClient') || die("Can't resolve myClient"); $textw = $top->Scrolled('Text', -scrollbars=>'osow', -wrap=>'none')-> pack(-fill=>'both',-side=>'left', -expand=>1); }, data=>sub{ $textw->insert(end=>$_[ARG0] . "\n"); $textw->update; }, }); }