in reply to A server that has a fool as its client: itself

First, it's necessary to understand the data flow.

The purpose is to take information it learns as a client and in turn repeat it to as a server to its clients.

So the flow is unidirectional?

sub run { for (;;) { my $msg = $connection_to_server->get(); $_->send($msg) for @connections_to_clients; } }

To get parallelism, send simply needs to hand off the work to a thread of some sort (including a separate process).

# Client class sub send { my ($self, $msg) = @_; $self->{work_queue}->enqueue($msg); } sub worker { my ($self) = @_; my $q = $self->{work_queue}; for (;;) { my $msg = $q->dequeue(); ... send $msg ... } }

Whether you use Coro, threads, forks or something else seems very incidental.

You could also use polling, but select loops tend to be complicated. The first I'd want to do is give the select loop the above enqueue/dequeue interface shown above. Might as well just use Coro to save the work.

Replies are listed 'Best First'.
Re^2: A server that has a fool as its client: itself
by Anonymous Monk on Feb 10, 2011 at 19:33 UTC
    So the flow is unidirectional?

    Ah, it's bidirectional. I should have clarified, my bad

    Think of these daemons acting as beacons relaying information to one another. Eventually, all the participants in the network of daemons in different places will have the same information.

Re^2: A server that has a fool as its client: itself
by Anonymous Monk on Feb 11, 2011 at 13:57 UTC

    Wow! thanks for that, it does give me a clue into doing this.