/ domm

I hack Perl for fun and profit

Follow me on twitter!
Atom Icom ... on Atom!
12.08.2017: Things I learned at the European Perl Conference 2017 in Amsterdam
04.08.2017: What I expect from a Web Framework
13.07.2017: Using a DarkPAN with Carton
02.01.2017: Vienna.pm Meeting dates for 2017 (as calculated by Perl 6)
23.12.2016: Announcing Plack::Middleware::PrettyException
13.09.2016: Too dumb for TCP

It seems I'm too dumb for handling raw TCP. Please, dear Internet, teach me what I'm doing wrong!

What I'm trying to do

I want to send some data to Telegraf via TCP. So I open a socket and send the data. All is well, until Telegraf is restarted, thus losing the connection to the sending script. So I want to catch the lost connection, reconnect, and send happily ever after...

The Problem

As soon as I stop Telegraf, the script justs exits, even though the call to send is packed in a lot of eval. So I guess I'm missing something obvious. Please point it out!

The Code

#!/usr/bin/env perl
use strict;
use warnings;

use IO::Socket::INET;

my $socket = IO::Socket::INET->new(
    PeerAddr => 'localhost',
    PeerPort => 8094,
    Proto    => 'tcp',

eval {
    while (1) {
        eval {
            $socket->send("test value=1i");
            print '.';
        warn $@ if $@;
warn $@ if $@;
Tags: sockets, help

Comments (via senph)

04.09.2016: Alpine Perl Workshop 2016
26.08.2016: Things I learned at the European Perl Conference 2016 in Cluj
26.07.2016: App::TimeTracker::Command::TellSlack
18.06.2016: Announcing Plack::App::ServiceStatus