in reply to
Telnet Client/Server: What am I doing wrong?
You have explained your problem, but without running examples, it is hard to say what is wrong. Try this Tk socket client, and see how it works.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use IO::Socket;
require Tk::ROText;
# create the socket
my $host = shift || 'localhost';
my $port = 7070;
my $socket = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
);
defined $socket or die "ERROR: Can't connect to port $port on $host: $
+!\n";
print STDERR "Connected to server ...\n";
my $mw = new MainWindow;
my $log = $mw->Scrolled(qw/ROText -scrollbars ose/)->pack;
my $txt = $mw->Entry()->pack(qw/-fill x -pady 5/);
$mw ->bind('<Any-Enter>' => sub { $txt->Tk::focus });
$txt->bind('<Return>' => [\&broadcast, $socket]);
$mw ->fileevent($socket, readable => sub {
my $line = <$socket>;
unless (defined $line) {
$mw->fileevent($socket => readable => '');
return;
}
$log->insert(end => $line);
});
MainLoop;
sub broadcast {
my ($ent, $sock) = @_;
my $text = $ent->get;
$ent->delete(qw/0 end/);
print $sock $text, "\n";
}