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

tail file and send over socket

P: 20
So I have this script and it works great at sending things over a socket after tailing a file. The problem seems to be when the recieving end is not available the program crashes. Is there a way to get the program to stay up and wait for the recieving end to be available?
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'; 
  10. my $port = 8264; 
  11.  
  12. my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp'); 
  13. $sock or die "no socket: $@"; 
  14.  
  15. chomp $ln;
  16. print $sock $line;
  17.  print "$line";
  18.  close $sock;
  19. }
  20. }

Thanks for the help!
Apr 8 '08 #1
Share this Question
Share on Google+
1 Reply


numberwhun
Expert Mod 2.5K+
P: 3,503
So I have this script and it works great at sending things over a socket after tailing a file. The problem seems to be when the recieving end is not available the program crashes. Is there a way to get the program to stay up and wait for the recieving end to be available?
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'; 
  10. my $port = 8264; 
  11.  
  12. my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp'); 
  13. $sock or die "no socket: $@"; 
  14.  
  15. chomp $ln;
  16. print $sock $line;
  17.  print "$line";
  18.  close $sock;
  19. }
  20. }

Thanks for the help!
Sorry, I don't know much about sockets, but hopefully one of our experts will be able to assist you.

Sorry for the delay in answering your question.

Regards,

Jeff
Apr 17 '08 #2

Post your reply

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