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);
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.