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

Re: [MacPerl] Client-Server Problems



At 5:13 PM 98.03.09, Jon Jacob wrote:

> 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?
>


Are you using NCSA telnet to connect to the server? If so, my experience
may be some help for you. (if not, please just ignore :-)

I myself once have written a simple server script like yours, run it on
Macintosh, and tried to connect to it with NCSA telnet (2.6.1d3 J7). I met
the same kind of problem. As far as I knew from experience (not from
theory), the problem was caused by some extra header which NCSA would send
to the server at the beginning of connection. Then my workaround was just
to remove this telnet spelling. I'll show it embedding into your code
(please note that this might be dependant on the different versions of NCSA
telnet) :

#!perl -w
$/ = "\015\012";
use strict;
use IO::Socket;
my($server, $client);

my $telnet_spell ="\xff\xfd\x01\xff\xfd\xff\xfc\x23"; # the header string
my $input; #

$server = IO::Socket::INET->new(Listen    => 5,
                              LocalAddr => 'localhost',
                              LocalPort => 9000,
                              Proto     => 'tcp') or die($@);
while ($client = $server->accept()) {

 $input = $client; #

 chomp($input); #
 $input = substr($input, length($telnet_spell)+1); # remove the header
 print $client "Connected to Server\015\012"; # just to notify the client

  while (<$client>) {
    s/\015?\012/\015/;
    print;
    last if /DONE/;
  }
  print $client "Connect!\015\012";
  print "Connect!\n";
  close($client);
}


Takashi Ikemi

Technology of Asia, Co., Ltd.



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