Hi all,

I'm trying to figure out whether this has been done before and/or 
looking for suggestions on the best way to implement it.

I would like the "publish" clients to connect to a server, then publish 
their message and disconnect.  (Optionally, they can stay connected and 
publish more messages.)

The "subscribe" clients would hold persistent connections to the server 
(there are only 2 subscribers, though there could be more) and receive 
the messages immediately after publication.

My first crack at implementing this involves forks and pipe opens where 
the publisher is given a list of filehandles which are (mostly) 
subscribers.  This drops some messages on the floor rather than sending 
them to the subscriber iff the publishers get in race (and repeating 
the race condition is difficult), but at least the overall form is 
roughly what I had in mind.

  http://scratchcomputing.com/svn/misc/pubsubserver

To put that in some rough but short code:

  my $fh;
  while(my $client = $socket->accept()) {
    my $pid = open($fh, '|-') and next;
    if(pub) {
      while(<$client>) { print $fh $_ }
    }
    else {
      while(<>) { relay_to_subscriber($client) }
    }
    exit;
  }

Nevermind the piped open, I'll probably just fork and use tempfiles or 
something.

The real question is:  before I start down the road of inventing a 
protocol, is there anything out there which already does it?  I note 
wikipedia's "publish/subscribe" and "observer pattern" have various 
links to implementations, but apparently there is no standard?

Failing that, my next step is to come up with some kind of scheme for 
performing delivery in distinct chunks (of YAML.)

Thanks,
Eric
-- 
Don't worry about what anybody else is going to do. The best way to
predict the future is to invent it.
--Alan Kay
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------

Reply via email to