#!/usr/bin/perl use Tk; use IO::Socket; ################################## # SOCKET CONFIG ################################## ($host, $port, $kidpid, $handle, $line); $handle = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "xxxxxxxx", PeerPort => xxxx) or die "can't connect to port $port on $host: $!"; $handle->autoflush(1); ################################## $newWindow = MainWindow->new(); $newWindow->title("Conversation"); $newWindow->geometry("400x600"); $getDisplay = $newWindow->Text(-width=>50, -state=>"normal", -relief=>"flat", -background=>"white")->grid("-","-"); $SendText = $newWindow->Entry(-width=>50, -background=>"white")->grid("-","-"); $SendText->focus; $SendText->icursor(1); $SendText->bind("", \&send); $newWindow->Button(-text=>"Send", -command=>sub{&send;})->grid( $newWindow->Button(-text=>"Focus Object"), $newWindow->Button(-text=>"Clear Reciever", -command=>sub{&clr;})); $userList = $newWindow->Listbox(-width=>50, -height=>10)->grid("-","-"); MainLoop; while (defined ($line = <$handle>)) { $getDisplay->insert('end', "--- $line\n", 'bold'); print $line; #print to console } sub send { $outboundText = $SendText->get(); $SendText->delete(0, 'end'); if (!$outboundText) { $outboundText = "*NULL STRING*"; } $getDisplay->insert('end', "$outboundText\n", 'bold'); print $handle $outboundText;; print "$outboundText"; } sub clr { $getDisplay->delete("1.0", 'end') }