473,396 Members | 1,914 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,396 software developers and data experts.

keeping perl code from aborting.

I have a simple socket client code that sends the contents of a syslog over to a server when it finds an error. It has been working fine in a while loop of read open socket send line and close socket. However I have been having network issues and have found the code is aborting whenever the network has issues. Is there a way to keep the code from aborting? here is the snippet that seems to cause the code to abort.
Expand|Select|Wrap|Line Numbers
  1. use File::Tail;
  2. use IO::Socket; 
  3. {
  4. local $/ = "\n";
  5. my $name = 'filename';
  6. $file=File::Tail->new(name=> $name, maxinterval=>3, reset_tail=>0);
  7. while (defined($line=$file->read)) {
  8. # init host and port 
  9. my $host = 'ip_address'; 
  10. my $port = 8265; 
  11.  
  12.  
  13.  
  14.  
  15. my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp'); 
  16. $sock or die "no socket: $@"; 
  17.  
  18. chomp $ln;
  19. print $sock $line;
  20.  print "$line";
  21.  close $sock;
  22. }
  23. }
  24.  
Thanks!!
Jan 7 '08 #1
2 1594
numberwhun
3,509 Expert Mod 2GB
I have a simple socket client code that sends the contents of a syslog over to a server when it finds an error. It has been working fine in a while loop of read open socket send line and close socket. However I have been having network issues and have found the code is aborting whenever the network has issues. Is there a way to keep the code from aborting? here is the snippet that seems to cause the code to abort.
Expand|Select|Wrap|Line Numbers
  1. use File::Tail;
  2. use IO::Socket; 
  3. {
  4. local $/ = "\n";
  5. my $name = 'filename';
  6. $file=File::Tail->new(name=> $name, maxinterval=>3, reset_tail=>0);
  7. while (defined($line=$file->read)) {
  8. # init host and port 
  9. my $host = 'ip_address'; 
  10. my $port = 8265; 
  11.  
  12.  
  13.  
  14.  
  15. my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp'); 
  16. $sock or die "no socket: $@"; 
  17.  
  18. chomp $ln;
  19. print $sock $line;
  20.  print "$line";
  21.  close $sock;
  22. }
  23. }
  24.  
Thanks!!
I am not sure about the aborting issues, as I don't have any experience with sockets, but you should really have the pragmas "use strict" and "use warnings" in all of your code. A number of the people here require it in your code as it cuts down on the typical errors that can be readily fixed, yet cause false issues compared to the real issue(s) at hand.

Regards,

Jeff
Jan 7 '08 #2
KevinADC
4,059 Expert 2GB
Maybe you can change the maxinterval value?

maxinterval=>3
Jan 7 '08 #3

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

Similar topics

3
by: FLOTServer | last post by:
Here's my problem: I run a gameserver that runs the game "Medal of Honor". On the game server is log file which contains all of the data from the players for that day (kills, deaths, etc...). I...
0
by: Jason | last post by:
I have a job created on my server which runs a stored procedure. The SP uses a cursor on a recordset to insert rows into a table (via a stored procedure - hence the cursor). It is expected that...
7
by: BarryS | last post by:
Hi All: We're rolling out 3 DB2 (8.2 on LUW) platforms for branch offices, each of these are going to have the same schema. These are all going to be non-federated systems. I need some advice...
1
by: johnny | last post by:
In a multi-threaded application, say a worker thread makes an asynchronous call and specifies a callback method. But before the callback is executed, the thread is aborted by its creator. What is...
15
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that...
7
by: archana | last post by:
Hi all, I am having application in which i am doing asynchronous call.I am using manualresetevent to wait for asynchronous call to complete. I want to stop asynchronous call after certain...
5
by: Nayan | last post by:
Hi, If I make a call to function which is in external library, and it goes into wait sate.. disabling my app to proceed further, how can I break this state elegantly? So far, I had to kill my...
2
by: ricco | last post by:
I have a web form created in html, on a web host server, which includes a start time field that can be up to 24 hours ahead. After hitting the submit button, a Perl script is run that takes the form...
3
by: alimsdb | last post by:
By using Formatter.pm in perl we can remove all html tags. But I want to keep tag <a href and remove all other tags. Can any body help me to change Formatter.pm file to do this task. sub a_start...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.