8 use IO::Socket::Multicast;
9 use Time::HiRes qw( gettimeofday );
14 my $port = $ENV{'LWES_PORT'} || 9191;
15 my $addr = $ENV{'LWES_ADDRESS'} || '224.0.0.69';
20 ( my $id = $0 ) =~ s/^.*\///; # basename;
21 STDERR->print(<<"EndOfUsage");
22 Usage: $id [options] <listener name> <args>
23 {-m|--addr} <multicast_address>
24 {-p|--port} <multicast_port>
25 {-s|--site_id} <siteid>
26 {-d|--debug} print extra debugging information
29 <args> are passed directly to the listener constructor
34 # Read the command line options
38 STDERR->print(join("\n",@_),"\n") if (@_);
45 's|site_id=s' => \$siteid,
47 'help' => \&printUsage,
51 my $listener = shift @ARGV;
53 unless ( defined($listener) ) {
54 $listener = "EventPrintingListener";
56 my $package_name = undef;
57 if ( $listener!~ /::/ ) {
58 $package_name = "LWES::Listeners::".$listener;
60 $package_name = $listener;
63 # Load the module and create an instance
64 eval "use $package_name;";
66 die "use $package_name failed ($@)";
69 my $listener_object = $package_name->new(@ARGV);
72 my $sock = IO::Socket::Multicast->new(LocalPort=>$port, Reuse=>1)
73 or die "Can't create socket: $!";
75 $sock->sockopt(SO_RCVBUF,(16*1024*1024));
77 # add multicast address
78 $sock->mcast_add($addr) or die "mcast_add: $!";
81 die "recv error: $!" unless $peer = recv($sock,$message,65535,0);
82 my ($port,$peeraddr) = sockaddr_in($peer);
84 my $event = bytesToEvent($message);
86 # set up a header similiar to the lwes header
87 my ($seconds, $microseconds) = gettimeofday;
88 $event->{'SenderPort'} = $port;
89 $event->{'SenderIP'} = inet_ntoa($peeraddr);
90 $event->{'ReceiptTime'}= $seconds*1000+int($microseconds/1000);
92 # let the listener process the event
93 $listener_object->processEvent($event);