I am trying to get a client to communicate with a server located on another host.  I 
can get the 2
to connect, the server to send data, and the client to receive the data on the other 
end but I can
not get the client to respond to the server.  I am a beginner with this so I don't 
really know
where the problem would lie, hopefully one of you do.  I got most of this from 
examples.  Here is
the server piece followed by the client.  Thanks in advance.

-Michael McQuarrie

#---------SERVER---------#

#!/usr/bin/perl

use IO::Socket;
use IO::Select;

$serverport = "1980";

$server = IO::Socket::INET->new(LocalPort => $serverport,
                                Type      => SOCK_STREAM,
                                Reuse     => 1,
                                Listen    => 10 )
  or die "Couldn't be a tcp server on port $serverport : $@\n";

$server->autoflush(1);

open (CLIENTIN, "> /home/mike/test/1/test7.out")
  or die "Couldn't open output file\n";

while ($client = $server->accept()) {
  $client->autoflush(1);
  print $client "What is your name?\n";
  chomp ($response = <$client>);
  print CLIENTIN "$response\n";
}


#---------CLIENT---------#

#!/usr/bin/perl

use strict;
use IO::Socket;

my ($host, $port, $kidpid, $handle, $line);

unless (@ARGV == 2) { die "usage: $0 host port" }
($host, $port) = @ARGV;

$handle = IO::Socket::INET->new(Proto    => "tcp",
                                PeerAddr => $host,
                                PeerPort => $port)
or die "Can't connect to port $port on $host: $!";

$handle->autoflush(1);
print STDERR "[Connected to $host:$port]\n";

die "Can't fork: $!" unless defined($kidpid = fork());

if ($kidpid) {
  while (defined ($line = <$handle>)) {
    print STDOUT $line;
  }
  kill ("TERM" => $kidpid);
}
else {
  while (defined ($line = <STDIN>)) {
    print $handle $line;
  }
}
exit;



__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to