Hi POE folks,

while writing a port forwarder similar to the one in the POE cookbook,
just by using POE::Component::Server::TCP and ::Client::TCP instead, I hit
a roadblock when it came to synchronizing the components.

After POE::Component::Server::TCP has started up (binding to the 'From'
port), if a client connects to it, the server will call the
client_connect callback, which I'm using to spawn an instance of
POE::Component::Client::TCP to connect to the 'To' port.

At this time, I need the server to wait accepting requests from the
connecting client *until* POE::Component::Client::TCP has connected to the
'To' port.

However, there's no way to say in the client_connect callback that the
server should not proceed to the 'client_request' stage yet.

I found a workaround by setting a global variable $CONNECTED in

  my $client_session =
    POE::Component::Client::TCP->new(
        # ...
        Connected => sub { $CONNECTED = 1; },
        # ...

and adding

  $kernel->run_one_timeslice() while !$CONNECTED;

to the client_request callback of the POE::Component::Server::TCP
server. This does the trick, but I don't like that it's a
global variable that allows only single use of this component.

Is there a better way?

-- Mike

Mike Schilli
m...@perlmeister.com

Reply via email to