ESTAR Event Broker
From EStar
About
The eSTAR project is actively collaborating with the RAPTOR project at Los Alamos and the VOEventNet project at Caltech to develop an event network as part of the Virtual Observatory (VO). As a result the project is currently serving as one of the test bed nodes in the emerging network.
If you wish to connect to the directly to the broker you should, in the first instance, contact Alasdair Allan. Alternatively you may wish to subscribe in near real-time via RSS
. The current status of the broker software, along with the rest of the eSTAR network, can be found on our Network Status pages.
Perl Client Software
A simple Perl client for connection to a mini-interop compliant event publisher (or broker) is shown below. This client makes use of the Astro::VO::VOEvent module which is available for download from the VOEvent Sourceforge Repository.
#!/usr/bin/perl
use IO::Socket;
use POSIX qw/:sys_wait_h/;
use Errno qw/EAGAIN/;
use Getopt::Long;
use Time::localtime;
use Astro::VO::VOEvent;
unless ( scalar @ARGV >= 2 ) {
die "USAGE: $0 [-host hostname] [-port portname]\n";
}
my ( $host, $port );
my $status = GetOptions( "host=s" => \$host,
"port=s" => \$port );
unless ( defined $host && defined $port ) {
$host = "CONTACT AA@ESTAR.ORG.UK FOR HOST";
$port = "CONTACT AA@ESTAR.ORG.UK FOR PORT";
}
SOCKET: {
print "Opening client connection to $host:$port\n";
my $sock = new IO::Socket::INET( PeerAddr => $host,
PeerPort => $port,
Proto => "tcp" );
unless ( $sock ) {
my $error = "$@";
chomp($error);
print "Warning: $error\n";
print "Warning: Trying to reopen socket connection...\n";
sleep 5;
redo SOCKET;
};
my $message;
print "Socket open, listening...\n";
my $flag = 1;
while( $flag ) {
my $length;
my $bytes_read = read( $sock, $length, 4 );
next unless defined $bytes_read;
print "\nRecieved a packet from $host...\n";
print "Time at recieving host is " . ctime() . "\n";
if ( $bytes_read > 0 ) {
print "Recieved $bytes_read bytes on $port from ".$sock->peerhost()."\n";
$length = unpack( "N", $length );
if ( $length > 512000 ) {
print "Error: Message length is > 512000 characters\n";
print "Error: Message claims to be $length long\n";
print "Warning: Discarding bogus message\n";
} else {
print "Message is $length characters\n";
$bytes_read = read( $sock, $message, $length);
print "Read $bytes_read characters from socket\n";
# callback to handle incoming Events
print $message . "\n";
my $object = new Astro::VO::VOEvent( XML => $message );
my $response;
if ( $object->role() eq "iamalive" ) {
$response = $message;
} else {
$response = "<?xml version='1.0' encoding='UTF-8'?>"."\n".
'<trn:Transport role="ack" version="0.1"'."\n".
' xmlns:trn="http://www.telescope-networks.org/xml/Transport/v0.1"'."\n".
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'."\n".
' xsi:schemaLocation="http://www.telescope-networks.org/xml/Transport/v0.1 v0.1.xsd">'."\n".
'<Origin>ivo://uk.org.estar/estar.ex#</Origin>'."\n".
'<TimeStamp>'. ctime() . '</TimeStamp>'."\n".
'</trn:Transport>'."\n";
}
my $bytes = pack( "N", length($response) );
print "Sending " . length($response) . "bytes to socket\n";
print $sock $bytes;
$sock->flush();
print $sock $response;
print "$response\n";
$sock->flush();
print "Done.\n";
}
} elsif ( $bytes_read == 0 && $! != EWOULDBLOCK ) {
print "Recieved an empty packet on $port from ".$sock->peerhost()."\n";
print "Closing socket connection...";
$flag = undef;
} elsif ( $bytes_read == 0 ) {
print "Recieved an empty packet on $port from ".$sock->peerhost()."\n";
print "Closing socket connection...";
$flag = undef;
}
unless ( $sock->connected() ) {
print "Warning: Not connected, socket closed...\n";
$flag = undef;
}
}
print "Warning: Trying to reopen socket connection...\n";
redo SOCKET;
}
exit;
