473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

IO::Socket::INET - 2 problems

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 :

Expand|Select|Wrap|Line Numbers
  1. $socket = IO::Socket::INET->new(
  2.     PeerAddr    => '10.100.1.232',
  3.     PeerPort    => 41004,
  4.     Type        => SOCK_STREAM,
  5.     Proto        => "tcp",
  6. );
  7.  
  8. if ($socket) {
  9.     if ($#ARGV >= 0) {
  10.         $socket->send($ARGV[0]);
  11.     } else {
  12.         $socket->send('TEST');
  13.         $mess = 'TEST send';
  14.         wlog($mess);
  15.         $socket->recv($instr,20);
  16.     }
  17.     $socket->close;
  18.     wlog('Server running and using port 41004');
  19.     exit;
  20. }
  21.  
  22. #--- Fork to free child and close parent
  23. $pid = fork;
  24. if ($pid) {
  25.     wlog('Closing parent process');
  26.     close(LOG);
  27.     exit;
  28. }
  29.  
The script loops receiving input messages :

Expand|Select|Wrap|Line Numbers
  1. $server = IO::Socket::INET->new(
  2.     LocalPort    => 41004,
  3.     Type        => SOCK_STREAM,
  4.     Reuse        => 1,
  5.     Listen        => 10,
  6. ) or die wlog("Cannot bind to port ");
  7.  
  8. while (($client,$peeradd) = $server->accept()) {
  9.     ($clientport,$clientadd) = unpack_sockaddr_in($peeradd);
  10.     $mess = "Server loop" . " " . inet_ntoa($clientadd) . " - " . $clientport;
  11.     wlog($mess);
  12.     #new
  13.  
  14.     $cadd = inet_ntoa($clientadd);
  15.     print $cadd . "\n";
  16.     #new
  17.     if ($cadd eq '10.') {
  18.         $mess = 'Bad store detected - abort';
  19.         next;
  20.     }
  21.     $rc = $client->timeout(10);
  22.  
  23.     $client->recv($instr,200);
  24.  
  25.     # if message = TEST etc etc
  26.  
  27.     if (substr($instr,0,4) eq 'TEST') {
  28.         $mess = 'TEST received';
  29.         wlog($mess);
  30.         $client->send('OK');
  31.         next;
  32.     }
  33. }
  34.  

much appreciated if you could offer any advice,

regards,

Clem
Jun 26 '07 #1
0 2305

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: anuradha.k.r | last post by:
hi, I 'v e written both the server and client side socket programs in perl( a very small one).My socket is created and shows that the connection is established with the client.however I am not...
0
by: Rad | last post by:
Im trying to lauch a small perl program in cygwin which listens for arguments on a specified port. When executing this line (18) ; my $sock = new IO::Socket::INET(LocalPort => $DAEMONPORT,...
1
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
8
by: kardon33 | last post by:
Currently i am working on a project to send a UDP packet through the ArtNet protocol and receive a message back and read and output it. right now i can send the message fine and the device i send it...
1
by: kardon33 | last post by:
How would i receive an incoming UDP packet in perl with IO::SOCKET::INET???
0
by: muraley | last post by:
Hi, This client-server script does bi-directional communication. Setup i used: The server script on windows 2003 server and the client on a linux machine. Since i faced issues in getting the...
1
by: Dimbeswar Pathak | last post by:
I got an error message "use" not allowed in expression at client.pl line 2, at end of line syntax error at client.pl line 2, near "use IO::Socket::INET" Execution of client.pl aborted due to...
4
by: pplers | last post by:
use IO::Socket; my $path= "http://website.com/aaa.php"; print q( __________ -/* Script v1.0 *\- ------------------ );
1
by: john2357 | last post by:
I can not use the LWP module, and must use IO::Socket. Using 'Wireshark' and Mozilla and passing in the parameters below I get a valid reply. However Wireshark shows HTTP needs to be 1.1 and that the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.