소켓에 대한 샘플 스크립트
이 샘플 스크립트는 소켓 스크립트의 작성 방법을 보여줍니다.
Perl 샘플
다음 샘플 Perl 스크립트는 소켓에 연결하고
데이터를 보냅니다. 이 샘플은 UNIX에서 실행되는 에이전트에 대해 작성되었으며,
제품 코드는
k00이고 속성 그룹은 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;