Trisha Adams wrote: Wed 30/01/2002 9:11 PM
> I am very new to perl, so please excuse me if this is a 'newbie
> question.' I was recently trying to make a bot for irc using net::irc.
> I also made a gui interface for it using win32::gui. However,
> everytime I try to combine gui windows and the irc code, the program
> doesn't work. It works until I tell it $irc->start; or $W->Show().
> Do these two libraries conflict with each other or is there some way I
> can use a gui interface and connect with net::irc?
yes, the two libraries "conflict" with each other, at a conceptual level:
they're both event-based. when you call $irc->start, Net::IRC takes the
control of your program flow and calls handlers when it feels the need (eg.
when something happens on the connection).
Win32::GUI does pretty much the same. when you call $W->Dialog(), it takes
the control flow and calls events when it feels the need (eg. when you
interact with the GUI).
there are 2 possible solutions: the first, and better, but harder to reach,
is to resort to some kind of multitasking (eg. let Net::IRC and Win32::GUI
run in parallel and communicate each other).
the worst, but easier, solution, is to let one of the two modules do its
stuff only in the "spare time" of the other one. of course, when one of the
two modules is actively working on something, the other one will be freezed.
so while you're trasferring data over the IRC channel, the GUI will hang up,
and while you're doing something on your window, the IRC communication will
be paused. this is suboptimal in principle, but feel free to do your tests
and decide if the lag it's acceptable.
quoted from the Net::IRC documentation:
If you're tying Net::IRC into another event-based module, such as
perl/Tk, there's a nifty do_one_loop() method provided for your
convenience. Calling $irc->do_one_loop() runs through the IRC.pm event
loop once, hands all ready filehandles over to the appropriate handler
subs, then returns control to your program.
do_one_loop() is the way to go (Win32::GUI is, in fact, another event-based
module). take a look at Win32::GUI::Timer, and add a Timer event to your
window that will call Net::IRC do_one_loop() repeatedly.
cheers,
Aldo
__END__
$_=q,just perl,,s, , another ,,s,$, hacker,,print;
-----Original Message-----
From: John V. Pataki [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 18, 2002 8:35 AM
To: perl-win32-users@listserv. ActiveState. com
Subject: multitasking - listening to a socket while remaining interactive or doing other tasksI am trying to write an perl/Tk application that will allow user interaction while at the same time monitoring a socket for other apps that want to talk to it.I seem to be able to do either or...I can write a simple server to listen to the socket as in the example below....(examples from O'reilly)-----------------------------use Socket;
use Carp;
sub logmsg { print "@_ at ", scalar localtime, "\n" }my $port = shift || 2345;
my $proto = getprotobyname('tcp');socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1))
or die "setsockopt: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) or die "bind: $!";
listen(Server,SOMAXCONN) or die "listen: $!";logmsg "server started on port $port";
my $paddr;
$SIG{CHLD} = \&REAPER;for ( ; $paddr = accept(Client,Server); close Client) {
my($port,$iaddr) = sockaddr_in($paddr);
my $name = gethostbyaddr($iaddr,AF_INET);
logmsg "connection from $name [",
inet_ntoa($iaddr), "] at port $port";
print Client "Hello there, $name, it's now ",
scalar localtime, "\n";
}-----------------------------------------or even a simpler one like this----------------------------------------use IO::Socket;
$sock = new IO::Socket::INET (LocalHost => 'localhost',
LocalPort => 1200,
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "Socket could not be created. Reason: $!" unless $sock;
while ($new_sock = $sock->accept()) {
while (defined ($buf = <$new_sock>)) {
print $buf;
}
}
close ($sock);---------------------------------------------------------and I have written several perk/Tk apps that do various items.But once, I add the socket listening code to the perl/Tk app... I am locked.Is there a way to have the same app listen to a socket and remain unlocked to do other tasks?It seems to me it would involve somehow making the listen or accept commands operate in an eval block or something.But I haven't gotten that to work yet.Thanks for any help,John