#!/usr/bin/perl -w use Tk; use strict; use IO::Socket; use File::Basename; my $server = '192.168.0.100'; my $port = 55555; my $mw = MainWindow->new; $mw->Label( -text => "\nURL to desired file" )->pack; my $url = $mw->Entry( -width => 100 )->pack; $mw->Label(-text => " ")->pack; ######################## SPACER my $button = $mw->Button( -text => 'Fetch', -command => sub{do_fetch($url)}, -padx => 10, )->pack; #$button->bind('', sub{do_fetch($url)}); $mw->Label(-text => " ")->pack; ######################## SPACER my $ent_msg; my $ent = $mw->Entry(-width => 100, -state => "readonly", -textvariable => \$ent_msg)->pack(); MainLoop; sub print_status { my $msg_txt = join(" ", @_); $ent_msg = $msg_txt; $ent->update(); } ################## CLIENT PORTION sub do_fetch { print_status("Submitted request to $server"); my $url = shift; my $url_val = $url->get; my $scriptname = basename($0); my $command = 'fetch'; my $msg = $url_val; unless($msg) { print "Usage: $scriptname \n"; exit; } chomp($msg); my $client = new IO::Socket::INET ( PeerAddr => $server, PeerPort => $port, Proto => "tcp", ) or die "Can't connect to $server:$port : $!\n"; print $client $command . " " . $msg . "\n"; my $response = <$client>; if ($response) { chomp($response); print_status("$response"); } } __END__