Gtk::Gdk->input_add() ?????



I'm having some problems with the input_add() function to assign a callback
to a socket when data is ready to be read from the socket.  Here is a simply
client/server program.. I have no idea why it doesn't work:

server waits for a connection, and then prints YO on the socket every 5
seconds.
client connects to the server and installs a Gtk::Gdk->input_add()handler
for the
socket

output is weird -- even though I only ask for status on ['read'], I get
exception
and write conditions as well.   also -- the main gtk dialog is NEVER shown..
it
seems too busy calling the callback.

what am I doing wrong here?
thanks in advance!

######################SERVER START
#!/usr/bin/perl
use strict;
use IO::Socket;
my $s = IO::Socket::INET->new(LocalPort => 9009, Type => SOCK_STREAM, Reuse
=> 1, Listen => 10)
        or die "cannot serve\n";
my $client;
while($client = $s->accept()) {
        while(1) { print $client "YO"; sleep 5;}
}
close($s);
######################SERVER END

######################CLIENT START
#!/usr/bin/perl
use strict;
use IO::Socket;
use Gtk;
use Gtk::Gdk;

init Gtk;
my $w = new Gtk::Window -toplevel;
$w->signal_connect( destroy => sub {exit} );

my $s = IO::Socket::INET->new(PeerAddr => "localhost",
PeerPort=>9009,Proto=>"tcp",Type=>SOCK_STREAM) or die "cannot create
client.\n";

Gtk::Gdk->input_add($s->fileno(), ['read'], \&cb);

sub cb {
   my ($source, $condition) = @_;
    my %c = %$condition;

    print "   source: $source    condtn: ";
    foreach(keys %c) {
        print $_,"->",$c{$_}," ";
    }
    print "\n";
        sleep 1;
}

my $NAME = 'Button';
show $w;
my $b = new Gtk::Button 'pair';
$w->add($b);
show $b;
main Gtk;
######################CLIENT END


-Jon Oringer
SurfSecret Software
http://www.surfsecret.com





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]