I have purchased the PERL DEV Kit. And i have successfully created a Service. However here is the problem when i install the service it dosnt run, actually it wont even install. Here is the code that I am using:
----------------------------------------------------
use strict;
use IO::Socket;
# Set Service Info
my $listen_port = "1116"; # Receive from Client on this Port
my $client = ""; # Client Inbound Hash
my $line = ""; # Inbound Data
my $client_ip = ""; # Remote Host IP
my $data_port = "1117"; # Send Data out this Port
my $check_client = "192.168.1.11"; # Receiving Server
my $accept_from = "192.168.1.11"; # Accept Comms from this IP ONLY
# Start Listening
&LISTEN;
# Listen
sub LISTEN {
my $server = IO::Socket::INET -> new # Start Listening
(
LocalPort => $listen_port,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 5
) or die "Could Not initiate Port $listen_port!";
my($new_sock, $c_addr, $buf);
while (($client, $c_addr) = $server -> accept()) {
my ($client_port, $c_ip) = sockaddr_in($c_addr);
my $client_host = gethostbyaddr($c_ip, AF_INET);
my $client_ip = inet_ntoa($c_ip);
$line = <$client>;
print "Inbound connection from: $client_host @ $client_ip";
print "\n";
# Test inbound Connection
if ($client_ip ne $accept_from) {
print "Connection Refused\n";
close ($server);
&LISTEN;
} else {
chomp($line);
# What Do I do with the Inbound $line??
if ($line eq 'Test') {
my $socket = IO::Socket::INET -> new # Out Bound Client
(
PeerAddr => $check_client,
PeerPort => $data_port,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not Reach client: $check_client!\n";
print $socket "Test Complete.\n";
close($socket);
# Application Log
} elsif ($line eq 'Log Application') {
my $socket = IO::Socket::INET -> new # Out Bound Client
(
PeerAddr => $check_client,
PeerPort => $data_port,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not Reach client: $check_client!\n";
print $socket "Sending Application Log.\n";
close($socket);
}
}
}
close ($server);
}
package PerlSvc;
our %Config;
sub Startup {
# here's where your startup code will go
while (ContinueRun(60)) {
# Start Listening
&LISTEN;
}
}
# Set Service Info
sub Pause {
# your service is about to be suspended
}
sub Continue {
# your service will resume execution now
}
sub Interactive {
# this callback is invoked when your service is not running as
# a service and has been called without any of the --help,
# --install or --remove options.
}
sub Install {
$Config{ServiceName} = 'Network-Nerds';
$Config{DisplayName} = 'Network-Nerds';
# add your additional install messages or functions here
print "\nAdditional install notes\n";
}
sub Remove {
$Config{ServiceName} = 'Network-Nerds';
# add your additional remove messages or functions here
print "\nAdditional remove notes\n";
}
sub Help {
# add your additional help messages or functions here
print "\nAdditional help notes\n";
}
----------------------------------------------------
What am i doing wrong??
- Scott
Wise men ask questions, only fools keep quite.
----------------------------------------------------
use strict;
use IO::Socket;
# Set Service Info
my $listen_port = "1116"; # Receive from Client on this Port
my $client = ""; # Client Inbound Hash
my $line = ""; # Inbound Data
my $client_ip = ""; # Remote Host IP
my $data_port = "1117"; # Send Data out this Port
my $check_client = "192.168.1.11"; # Receiving Server
my $accept_from = "192.168.1.11"; # Accept Comms from this IP ONLY
# Start Listening
&LISTEN;
# Listen
sub LISTEN {
my $server = IO::Socket::INET -> new # Start Listening
(
LocalPort => $listen_port,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 5
) or die "Could Not initiate Port $listen_port!";
my($new_sock, $c_addr, $buf);
while (($client, $c_addr) = $server -> accept()) {
my ($client_port, $c_ip) = sockaddr_in($c_addr);
my $client_host = gethostbyaddr($c_ip, AF_INET);
my $client_ip = inet_ntoa($c_ip);
$line = <$client>;
print "Inbound connection from: $client_host @ $client_ip";
print "\n";
# Test inbound Connection
if ($client_ip ne $accept_from) {
print "Connection Refused\n";
close ($server);
&LISTEN;
} else {
chomp($line);
# What Do I do with the Inbound $line??
if ($line eq 'Test') {
my $socket = IO::Socket::INET -> new # Out Bound Client
(
PeerAddr => $check_client,
PeerPort => $data_port,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not Reach client: $check_client!\n";
print $socket "Test Complete.\n";
close($socket);
# Application Log
} elsif ($line eq 'Log Application') {
my $socket = IO::Socket::INET -> new # Out Bound Client
(
PeerAddr => $check_client,
PeerPort => $data_port,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not Reach client: $check_client!\n";
print $socket "Sending Application Log.\n";
close($socket);
}
}
}
close ($server);
}
package PerlSvc;
our %Config;
sub Startup {
# here's where your startup code will go
while (ContinueRun(60)) {
# Start Listening
&LISTEN;
}
}
# Set Service Info
sub Pause {
# your service is about to be suspended
}
sub Continue {
# your service will resume execution now
}
sub Interactive {
# this callback is invoked when your service is not running as
# a service and has been called without any of the --help,
# --install or --remove options.
}
sub Install {
$Config{ServiceName} = 'Network-Nerds';
$Config{DisplayName} = 'Network-Nerds';
# add your additional install messages or functions here
print "\nAdditional install notes\n";
}
sub Remove {
$Config{ServiceName} = 'Network-Nerds';
# add your additional remove messages or functions here
print "\nAdditional remove notes\n";
}
sub Help {
# add your additional help messages or functions here
print "\nAdditional help notes\n";
}
----------------------------------------------------
What am i doing wrong??
- Scott
Wise men ask questions, only fools keep quite.