NAME

Event::Lite::Server - Event dispatch server

SYNOPSIS

Basic Server

use Event::Lite::Server;

my $server = Event::Lite::Server->new(
  address => '127.0.0.1',
  port    => 34343,
);
$server->run();

# Do stuff...
think();

# Or even:
$SIG{TERM} = $SIG{INT} = sub {
  $server->stop();
};

#Finally:
$server->stop();

More Secure Server

use Event::Lite::Server;

my $server = Event::Lite::Server->new(
  address                     => '127.0.0.1',
  port                        => 34343,
  on_authenticate_subscriber  => \&check_subscriber,
  on_authenticate_publisher   => \&check_publisher,
);
$server->run();

# Do stuff...
think();

# Or even:
$SIG{TERM} = $SIG{INT} = sub {
  $server->stop();
};

#Finally:
$server->stop();

sub check_subscriber {
  my ($socket, $event_type, $username, $password) = @_;
  
  # Return a true value to authorize:
  if( $username eq 'admin' && $password eq 'swordfish' )
  {
    # Permission granted:
    return 1;
  }
  else
  {
    # Permission denied:
    return 0;
  }# end if()
}

sub check_publisher {
  my ($socket, $event_type, $username, $password) = @_;
  
  # Return a true value to authorize:
  if( $username eq 'admin' && $password eq 'swordfish' )
  {
    # Permission granted:
    return 1;
  }
  else
  {
    # Permission denied:
    return 0;
  }# end if()
}

DESCRIPTION

Event::Lite::Server does only one thing: Dispatch events from "publishers" to "subscribers" - nothing more, nothing less.

The other details (i.e. security) are left up to you, the user.

TECH SPECS

Performance

Depending on the size of the event, the number of subscribers and network latency, performance could range anywhere from 100 to 1,000 events per second. YMMV.

"Patches Welcome"

Protocol

Event::Lite uses a simple text-based protocol. The event body is base64-encoded JSON. Internaly, JSON::XS is used to encode and decode the data.

Subscribe

A subscribe request looks like this:

subscribe/event-name:username|password

So, to subscribe to events named "foo" you would send:

subscribe/foo:admin|swordfish

Publish

A publish request looks like this:

publish/event-name:username|password

<base64-encoded JSON>

So, to publish an event named "foo" you would send:

publish/foo:admin|swordfish

AB384dsd93jk4j2h3g4jh23g4jh2g34jhg234jhg23jh4g==

Receiving an Event

When a subscriber receives an event that it has subscribed to, that event is just the base64-encoded JSON.

AB384dsd93jk4j2h3g4jh23g4jh2g34jhg234jhg23jh4g==

Decoding it and parsing the resulting JSON will result in the event object itself.

SUPPORT

Visit http://www.devstack.com/contact/ or email the author at <jdrago_999@yahoo.com>

Commercial support and installation is available.

AUTHOR

John Drago <jdrago_999@yahoo.com>

COPYRIGHT AND LICENSE

Copyright (C) 2008 by John Drago

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.