473,799 Members | 3,080 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

keeping perl code from aborting.

20 New Member
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 1615
numberwhun
3,509 Recognized Expert Moderator Specialist
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 Recognized Expert Specialist
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
15284
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 have a perl script that runs on my webserver, which is supposed to login to the gameserver and download the log. The problem is that when it gets to the part where it needs to download the file, it aborts. The gameserver FTP requires I use port 24...
0
4382
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 some inserts will fail due to missing information or that a record already exists for it. One of the main reasons for me using the cursor is so that ALL the data is not rolled back when this occurrs. But it seems that when I run the job, the...
7
2063
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 / pointers on keeping the DDL's in sync with each other. I'm going to have a development machine in my office that I first apply any schema / stored-procedure changes to, then would like to roll out
1
2624
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 the expected behavior for this scenario? Does the thread stay alive until the callback is executed? If an exception is thrown, can it be caught? I posted this message last week, but got no response. I am really hoping someone can help me with...
15
11790
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 performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join() coupled with a Thread.Abort() but this does not kill the thread. Based on...
7
6807
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 period of time. I want something like thread.abort for aborting aynchronous call. Can someone tell me way of aborting asynchronous call.
5
1866
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 process. Someone suggested to code multi-threaded app in which one can monitor other and if one goes into locked state, other kills it. It sounds okay, but I don't know how to do it. Any code sample or
2
1432
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 data and accesses a website, with the data, at the requested start time. Without running this on my own server, instead of a public server, I'm unable to keep the connection live for anything more than 5-10 minutes. Any ideas?
3
2259
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 { #shift->{anchor}++; #1; } sub a_end {
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.