TheVend has asked for the wisdom of the Perl Monks concerning the following question:
I need to detect but not interfere with a network port.
In short I want a script that listens on port 2000 in tandem with another application. This script will trigger a batch file when the port is active. What is happening now is when this script runs it blocks the other app. Any wisdom is welcome.
My current attempt:use warnings; # use strict; use IO::Socket; use Socket; my $port = shift || 2000; my $socket = IO::Socket::INET->new( LocalPort => $port, Type => SOCK_STREAM, Reuse => 1, Listen => 10, ) or die "Couldn't create server: $@\n"; while (my $client = $socket->accept()) { my ($port, $iaddr) = unpack_sockaddr_in($client->peername()); #### GET TIME #### $t = time(); my $then = localtime($t); #### GET IP #### my $ip_address = inet_ntoa($iaddr); open(PLOT,">>label-log.txt") || die("This file will not open!"); seek PLOT,0,2; print PLOT "$ip_address $then \n"; close(PLOT); sleep(5); system ("start /b C:\\momlabels\\transfer.bat"); $client->send(inet_ntoa($iaddr)); $client->close(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Networking with IO::Socket
by stevieb (Canon) on Nov 30, 2015 at 01:31 UTC | |
by NetWallah (Canon) on Nov 30, 2015 at 01:59 UTC | |
by stevieb (Canon) on Nov 30, 2015 at 02:51 UTC | |
|
Re: Networking with IO::Socket
by TheVend (Novice) on Nov 30, 2015 at 21:16 UTC | |
by Apero (Scribe) on Nov 30, 2015 at 22:01 UTC | |
by stevieb (Canon) on Dec 01, 2015 at 00:33 UTC |