On Sep 5, 2005, at 17:43, Jay Strauss wrote:
I'm getting "POE::Kernel's run() method was never called." error
when my script that calls the code below ends.
I could put a ->run and ->("shutdown") into a sub DESTROY. But is
there a way I'm supposed to avoid this error.
POE::Kernel isn't designed to run without run() being called from the
top level. Your code avoids some initialization and cleanup that run
() does.
You could write a procedural library that talks to a POE server,
using POE::Filter::Reference without Client::TCP. Here's some code
extracted from one of my side projects. It's not tested outside the
context of its native project. The code could also use some error
checking.
my $socket = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
);
my ($buffer, $read_length);
sub msg_send {
my $message = shift;
my $streamable = nfreeze $message;
$streamable = length($streamable) . chr(0) . $streamable;
my $len = length($streamable);
while ($len > 0) {
if (my $w = syswrite($socket, $streamable, 4096)) {
$len -= $w;
}
else {
last;
}
}
}
sub msg_read {
while (1) {
if (defined $read_length) {
if (length($buffer) >= $read_length) {
my $message = thaw(substr($buffer, 0, $read_length, ""));
$read_length = undef;
return $message;
}
}
elsif ($buffer =~ s/^(\d+)\0//) {
$read_length = $1;
next;
}
my $octets_read = sysread($socket, $buffer, 4096, length($buffer));
return unless $octets_read;
}
}
--
Rocco Caputo - [EMAIL PROTECTED]