#!/usr/bin/perl #server.pl use strict; use IO::Socket::INET; $| = 1; #auto flush my ($socket,$client, $peerAddress, $peerPort); $socket = new IO::Socket::INET ( LocalHost => '127.0.0.1', LocalPort => '5000', Proto => 'tcp', Listen => 5, Reuse => 1, ) || die "cannot create socket $!\n"; print "listening for client connection on 3083\n"; while(1) { # waiting for new client connection. $client = $socket->accept(); $peerAddress = $client->peerhost(); $peerPort = $client->peerport(); print "Accepted New Client Connection From: $peerAddress $peerPort\n"; } $socket->close(); #### #!/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; }