Sample script for socket
This samples script demonstrates how a socket client might be written.
Perl sample
The following sample Perl script connects to a socket
and sends data. This sample was written for an agent that runs on UNIX, with the product code
k00 and
an attribute group called SocketData. #!/usr/bin/perl -w
# SocketTest.pl
# A simple Agent Builder Socket client using IO:Socket
#------------------------
use strict;
use IO::Socket;
# Initialize socket connection to the agent
#-----------------------
my $host = '127.0.0.1';
my $port = 0;
# This sample is for an agent with the k00 product code. The product code is
# used in the following line to find the file containing the port number to use.
open PORTFILE, "/tmp/k00_cps.properties" || die "Port file not found $!\n";
while (<PORTFILE>) {
if (/^CP_PORT=([0-9]+)/) {
$port = $1;
}
}
if ($port == 0) {
die "Could not find port to use to connect to agent.\n";
}
my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port,
Proto => 'tcp'); $sock or die "no socket :$!";
# The following call sends 2 rows of data to the agent. Each row contains 1
# String attribute and 3 numeric attributes.
syswrite $sock, "<socketData><attrGroup name=\"SocketData\"><in><a v=\"A message
from perl\"/> \<a v=\"1\"/><a v=\"2\"/><a v=\"123\"/></in><in><a v=\"More from
perl\"/><a v=\"456\"/> \<a v=\"123\"/><a v=\"789\"/></in></attrGroup>
</socketData>\n";
close $sock;