Hi,
i have a script that listens on a port for simple text messages and then
executes sql to a remote mssql database . The script is started via crontab .
There are 2 problems :
1 . The line to the remote database appears to go to sleep in the sense that the script receives a null return from the database instead of a message containing the number of rows affected by the sql . The sql in such a case does not get executed against the database, i.e. no updates are done.
2. The line sometimes fails with 'connection refused' or 'Error: Global alarm in 5'
2 code excerpts that may be relevant :
The script TESTS the port at start and forks if the port is not accepting TEST messages :
[CODE=perl]
$socket = IO::Socket::INE T->new(
PeerAddr => '10.100.1.232',
PeerPort => 41004,
Type => SOCK_STREAM,
Proto => "tcp",
);
if ($socket) {
if ($#ARGV >= 0) {
$socket->send($ARGV[0]);
} else {
$socket->send('TEST') ;
$mess = 'TEST send';
wlog($mess);
$socket->recv($instr,20 );
}
$socket->close;
wlog('Server running and using port 41004');
exit;
}
#--- Fork to free child and close parent
$pid = fork;
if ($pid) {
wlog('Closing parent process');
close(LOG);
exit;
}
[/CODE]
The script loops receiving input messages :
[CODE=perl]
$server = IO::Socket::INE T->new(
LocalPort => 41004,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10,
) or die wlog("Cannot bind to port ");
while (($client,$peer add) = $server->accept()) {
($clientport,$c lientadd) = unpack_sockaddr _in($peeradd);
$mess = "Server loop" . " " . inet_ntoa($clie ntadd) . " - " . $clientport;
wlog($mess);
#new
$cadd = inet_ntoa($clie ntadd);
print $cadd . "\n";
#new
if ($cadd eq '10.') {
$mess = 'Bad store detected - abort';
next;
}
$rc = $client->timeout(10);
$client->recv($instr,20 0);
# if message = TEST etc etc
if (substr($instr, 0,4) eq 'TEST') {
$mess = 'TEST received';
wlog($mess);
$client->send('OK');
next;
}
}
[/CODE]
much appreciated if you could offer any advice,
regards,
Clem
i have a script that listens on a port for simple text messages and then
executes sql to a remote mssql database . The script is started via crontab .
There are 2 problems :
1 . The line to the remote database appears to go to sleep in the sense that the script receives a null return from the database instead of a message containing the number of rows affected by the sql . The sql in such a case does not get executed against the database, i.e. no updates are done.
2. The line sometimes fails with 'connection refused' or 'Error: Global alarm in 5'
2 code excerpts that may be relevant :
The script TESTS the port at start and forks if the port is not accepting TEST messages :
[CODE=perl]
$socket = IO::Socket::INE T->new(
PeerAddr => '10.100.1.232',
PeerPort => 41004,
Type => SOCK_STREAM,
Proto => "tcp",
);
if ($socket) {
if ($#ARGV >= 0) {
$socket->send($ARGV[0]);
} else {
$socket->send('TEST') ;
$mess = 'TEST send';
wlog($mess);
$socket->recv($instr,20 );
}
$socket->close;
wlog('Server running and using port 41004');
exit;
}
#--- Fork to free child and close parent
$pid = fork;
if ($pid) {
wlog('Closing parent process');
close(LOG);
exit;
}
[/CODE]
The script loops receiving input messages :
[CODE=perl]
$server = IO::Socket::INE T->new(
LocalPort => 41004,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 10,
) or die wlog("Cannot bind to port ");
while (($client,$peer add) = $server->accept()) {
($clientport,$c lientadd) = unpack_sockaddr _in($peeradd);
$mess = "Server loop" . " " . inet_ntoa($clie ntadd) . " - " . $clientport;
wlog($mess);
#new
$cadd = inet_ntoa($clie ntadd);
print $cadd . "\n";
#new
if ($cadd eq '10.') {
$mess = 'Bad store detected - abort';
next;
}
$rc = $client->timeout(10);
$client->recv($instr,20 0);
# if message = TEST etc etc
if (substr($instr, 0,4) eq 'TEST') {
$mess = 'TEST received';
wlog($mess);
$client->send('OK');
next;
}
}
[/CODE]
much appreciated if you could offer any advice,
regards,
Clem