By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

keeping perl code from aborting.

P: 20
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
Share this Question
Share on Google+
2 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
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
Expert 2.5K+
P: 4,059
Maybe you can change the maxinterval value?

maxinterval=>3
Jan 7 '08 #3

Post your reply

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