in reply to Re^2: CLIENT help!
in thread CLIENT help!

I tried it, and added the lines:

my $output = `perl the-script.pl`; print CLIENT $output;

But it just prints "smile from the server" and doesnt run the perl program. :-/

Here is the total code:

#! /usr/bin/perl -w # server0.pl #-------------------- #use strict; use Socket; # use port 7890 as default my $port = shift || 7890; my $proto = getprotobyname('tcp'); # create a socket, make it reusable socket(SERVER, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1) or die "setsock: $!"; # grab a port on this machine my $paddr = sockaddr_in($port, INADDR_ANY); # bind to a port, then listen bind(SERVER, $paddr) or die "bind: $!"; listen(SERVER, SOMAXCONN) or die "listen: $!"; print "SERVER started on port $port "; # accepting a connection my $client_addr; while ($client_addr = accept(CLIENT, SERVER)) { # find out who connected my ($client_port, $client_ip) = sockaddr_in($client_addr); my $client_ipnum = inet_ntoa($client_ip); my $client_host = gethostbyaddr($client_ip, AF_INET); # print who has connected print "got a connection from: $client_host","[$client_ipnum] "; # send them a message, close connection print CLIENT "Smile from the server\n"; # open CLIENT, ("system ("perl io-test-1.pl");"); # open (CLIENT, "system ("perl io-test-1.pl")"); # open CLIENT, "do `perl io-test-1.pl`"; #my $status = CLIENT, system("perl io-test-1.pl"); #CLIENT $status = CLIENT, system("perl io-test-1.pl"); my $output = `perl io-test-1.pl`; print CLIENT $output; close CLIENT; }

Replies are listed 'Best First'.
Re^4: CLIENT help!
by Anonymous Monk on Jun 11, 2012 at 14:53 UTC

    So, what does io-test-1.pl do? Does it actually generate output? Does it compile? Does it even exist?

    PS: commenting out your use strict; is a pretty bad idea. Ignoring problems doesn't solve them...

      'io-test-1.pl' is a small program that has some basic commands, just a little command interpreter. I wrote it inspired of www.telehack.com's interface, and I can upload the code so far if you would like me to. Should I get rid of the 'use strict'? D:

        So just to clarify, you want io-test-1.pl to run interactively over the telnet connection?

        If that is the case, why not just move the socket handling into io-test-1.pl and bind that to the socket you're listening too?