in reply to Telnet Client/Server: What am I doing wrong?
#!/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"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Telnet Client/Server: What am I doing wrong?
by PM_Visitor (Initiate) on Dec 15, 2012 at 17:22 UTC | |
by zentara (Cardinal) on Dec 16, 2012 at 07:13 UTC | |
by PM_Visitor (Initiate) on Dec 27, 2012 at 00:40 UTC | |
by eyepopslikeamosquito (Archbishop) on Dec 16, 2012 at 00:45 UTC |