473,396 Members | 1,766 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.

tail file and send over socket

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
1 3043
numberwhun
3,509 Expert Mod 2GB
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

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

Similar topics

2
by: Jody Burgess | last post by:
Hi; I am writing my first python program and would like to know how to change stdout to refer to my default printer or any other printer on my network. The other question is, Is there an API set...
1
by: ADE | last post by:
Hi everyone well from my last post I found what I am looking for I have some code now that transfers files I have added a GUI to it and need some help with two things one my loadtemplate()...
4
by: zelzel.zsu | last post by:
I wrote two simple socket program. one for sending a file and the other for receiving the file. but when I run it, a curious thing happened. The received file was samller that the sent file. $...
6
by: Jesse Engle | last post by:
i'm working on two client and server programs that send and recieve files using sockets. i saw a c++ example using csockets, and thought i could use the basic idea of what the code was doing to...
11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
4
by: gvijayaratnam | last post by:
Hi All, I have a fn prototype as follows void print ( char *Buffer, usigned long bufferSize, int chunkSize ); This fn will accept binary file buffer and the buffer size and the chunk size,...
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: 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?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.