tail file and send over socket

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cookspyder
    New Member
    • Jul 2007
    • 20

    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?
    [CODE=perl]
    use File::Tail;
    use IO::Socket;
    {
    local $/ = "\n";
    my $name = 'filename';
    $file=File::Tai l->new(name=> $name, maxinterval=>3, reset_tail=>0);
    while (defined($line= $file->read)) {
    # init host and port
    my $host = 'ip';
    my $port = 8264;

    my $sock = new IO::Socket::INE T( PeerAddr => $host, PeerPort => $port, Proto => 'tcp');
    $sock or die "no socket: $@";

    chomp $ln;
    print $sock $line;
    print "$line";
    close $sock;
    }
    }[/CODE]


    Thanks for the help!
    Last edited by eWish; Apr 8 '08, 08:42 PM. Reason: Please use code tags
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by cookspyder
    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?
    [CODE=perl]
    use File::Tail;
    use IO::Socket;
    {
    local $/ = "\n";
    my $name = 'filename';
    $file=File::Tai l->new(name=> $name, maxinterval=>3, reset_tail=>0);
    while (defined($line= $file->read)) {
    # init host and port
    my $host = 'ip';
    my $port = 8264;

    my $sock = new IO::Socket::INE T( PeerAddr => $host, PeerPort => $port, Proto => 'tcp');
    $sock or die "no socket: $@";

    chomp $ln;
    print $sock $line;
    print "$line";
    close $sock;
    }
    }[/CODE]


    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

    Comment

    Working...