#!/usr/bin/perl # client.pl use strict; use IO::Socket::INET; # start connecting to socket &connectToSocket(0); exit; # handles the socket retries and network device output sub connectToSocket() { my $retry = shift; my $localt = localtime(); print "retry\t$retry\n"; $retry++; my $socket = &openSocket($retry); print "TCP Connection Success.\n"; # process input from network device while (<$socket>) { print "$_"; } # reconnect if socket drops &connectToSocket(0); } # creates the socket connection to the network device sub openSocket() { my $retry = shift; my $socket = IO::Socket::INET->new ( Proto => "tcp", PeerAddr => "192.168.1.105", PeerPort => "5000", Timeout => "1", ) || &connectToSocket($retry); $socket->autoflush(1); return $socket; }