Basically I am trying to write my own cgi-NMS for a small fleet a DACSes. They are just really dumb TCP servers for the purpose of this discussion. The server is running a raw socket that I can just attach to, auth, and command in. I have been having trouble recieving all the data that is sent the the client I built. The server sends a ';', semilcolon, as the command prompt. This is sent on its own line and it is the last line of the response. The client randomly breaks because it never gets one of the semicolons. I know this because I watch the tests I run with Ethereal. The client is not running in nonblocking mode. Would that fix this? The read sub is below. How can I ensure that these "lone" prompts are always received by PERL. They are always sent-I see them in the TCP session, yet PERL somehow never sees them. Someone suggested sending another command or a newline to force another prompt but that wont work cause I run multiple commands in series based on the users request. Any ideas?
sub read_sock
{
my(
$rout,
$wout,
$win,
$eout,
$ein,
$found,
$line,
$timeleft,
$read_status,
@out
);
#my $sock_read = $$sock_global;
my $buf='';
my $prompt = $_[0];
my $prompt_check = $_[1] || 1;
my $prompt_match=0;
my $timeout = 0;
my $rin = ''; # Initialise to an empty set
# (NOTE: $rin=0 is very wrong)
vec($rin, fileno($sock), 1) = 1; # Set the appropriate bit
while($prompt_match < $prompt_check)
{
($found,$timeleft) = select($rout=$rin,$wout=$win,$eou
+t=$ein,$timeout);
if ($found == 1)
{
$read_status=0;
#print "FOUND:"."$found\n";
$read_status = sysread($sock,$line,1024);
if($read_status)
{
$buf = "$buf"."$line";
}
if($line =~ /$prompt/)
{
#print "match found\n";
$prompt_match++;
}
}
}
@out = split(/\r/,$buf);
return(\@out);
}