[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Client-Server Problems



>#!perl -w
>$/ = "\015\012";
>use strict;
>use IO::Socket;
>my($server, $client);
>$server = IO::Socket::INET->new(Listen    => 5,
>                              LocalAddr => 'localhost',
>                              LocalPort => 9000,
>                              Proto     => 'tcp') or die($@);
>while ($client = $server->accept()) {
>  while (<$client>) {
>    s/\015?\012/\015/;
>    print;
>    last if /DONE/;
>  }
>  print $client "Connect!\015\012";
>  print "Connect!\n";
>  close($client);
>}
>
I apologize if this is not specific to MacPerl, but I am stumped and
frustrated.  If someone can direct me to a good list for this question that
would be great.

Chris Nandor sent me the above code to create a server that will accept
input.  I have that down and it works.  However, when I telnet to the port
(in my case 2345) I do not get the Connect! on the client-side.  In other
words, the Server does not appear to be printing to the client as it should
or the output to the buffer is being held.  Any ideas what is causing this?
 

Another weirdness is occurring.  I created a client program that sends data
to the server, rather than use the telnet.   Here is my client code:

#!/usr/bin/perl -w
use strict;
use IO::Socket;
my($host, $port, $kidpid, $handle, $line);
$handle = IO::Socket::INET->new(Proto => "tcp",
        PeerAddr => "localhost",
        PeerPort => 2345) or die $!;
$handle->autoflush(1);
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;
        }

This comes from the Llama book pg 249.  I am really confused because it
appears as if the buffer is being held until I break out of the client at
which point it prints the last entry to the server.  When it prints to the
server it overwrites all previous entries such that I input Hello World on
the first line, Goodbye on the second, then control-c out of it and the
server receives Goodbyeorld.  I thought this was part of autoflush's deal,
was I mistaken.  Should I define the buffer size so it writes when full?

I REALLY appreciate any help.  This is driving me nuts.

      ,,,,,
      /'^'\
     ( o o )
-oOOO--(_)--OOOo------------------------------------------------
                                           Jon Jacob
                                       xaviermoon@earthlink.net

  .oooO                                              541.488.8503
  (   )   Oooo.                                 Ashland, OR
---\ (----(   )-------------------------------------------------
    \_)    ) /
          (_/






***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch