use strict; use warnings; use Tk; use POE; use POE::Component::Client::HTTP::SSL; $|++; POE::Session->create( inline_states=> { _start => \&connect, send => \&send, get_input => \&get_input, listen => \&listen, }, ); $poe_kernel->run(); sub connect { my ($kernel,$heap,$session) = @_[KERNEL,HEAP,SESSION]; my $buf; my $mw = $poe_main_window; $heap->{txt} = $mw->Scrolled('Text',-width, 50,-height, 20,-scrollbars, 'osoe')->pack(-fill,'both',-expand, 1); $mw->Button(-text, 'Run', -command, $session->postback("send"))->pack; $kernel->yield("listen"); } sub send { my ($kernel,$session,$heap) = @_[KERNEL,SESSION,HEAP]; tie( *SSL, "POE::Component::Client::HTTP::SSL", "www.openssl.org", "443") or warn "can't open socket\n"; if( \*SSL ){ $heap->{sock} = \*SSL; $heap->{sock}->print("GET http://index.htm \r\n"); $kernel->yield('listen'); } } sub get_input { my ($kernel,$heap) = @_[KERNEL,HEAP]; $kernel->yield('listen'); } sub listen { my ($kernel,$session,$heap) = @_[KERNEL,SESSION,HEAP]; if(defined $heap->{sock}){ my $buf; $heap->{sock}->blocking(0); $heap->{sock}->read($buf, 1024); $heap->{txt}->insert('end',$buf); } $kernel->yield('get_input'); }