I have a service that listens for commands, when a command is received it echo's it back to the client and in a log. It works fine when I telnet from the terminal, but i'm having problems scripting it. It doesn't seem to write to the socket. I can read from the socket, but I can't write to it. Whatever I print to the socket from the script, it should be echoed back to me and logged on the server, but I don't see it in either place.
Upon connecting to the server, I receive:
Trying to aquire lock on log
Connection Established
Lock aquired
Then I send a string ending in a ;
FYI, in the server, $/ = ";";
I've tried just about everything I can think of...
Can anyone out there spot the error?
Thanks
#!/usr/bin/perl -w
use strict;
use IO::Socket::INET;
my $text = 'Hello;';
my $host = "10.10.30.130";
my $port = "5678";
my $sock = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp'
);
$sock or die "Can't connect to $host:$port\n";
#$sock->autoflush(1);
my $input = "";
my $char = "";
until ($input =~ /Lock aquired\s*$/){
sysread($sock, $char, 1);
$input .= $char;
}
print $input;
#$sock->send($text );
#syswrite $sock,$text ;
print $sock $text ;
$sock->shutdown(1);
close $sock;
exit;
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.