Hi,
I'd like rewrite some forking code to use POE instead.
I must connect to a server process via a tcp socket. The messages I
receive, are not terminated, but the individual fields are terminated by an
ASCII 0.
The first field received (message type), then tells me how many more fields
I must read to get the entire message.
In my current code I do it sorta like:
while (1) {
my $msgId = $self->receive;
if ($msgId == TICKPRICE) {$self->readTickPriceMessage}
...
}
sub readTickPriceMessage {
my $self = shift;
my @field = $self->receive() for (qw/tickerid tickType price/);
}
sub receive {
my $self = shift;
my $s = $self->socket;
my ($result,$byte);
while (sysread($s, $byte, 1) == 1) {
last if ord($byte) == 0;
$result .= $byte;
}
return $result;
}
But I'm trying to figure out how I'd do it with POE::Wheel::SocketFactory +
POE::Wheel::ReadWrite. It seems like I'm only going to get an event on the
initial connection. How would I get it to sit and listen on the socket for
messages? Furthermore, how would I get it to read a specific number of
fields based on the message ID?
Thanks
Jay