McMahon, Christopher x66156 wrote:
>      I think I'm missing a concept here...
>     I built a very simple TCP/IP server like the one on p. 441 of the
> Camel book.
>     But my server only ever sees the first message from any given
> client. Subsequent messages to my server are ignored.  Does anyone
> know what I have to do to get my server to handle more than one
> message? 
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> my ($server, $server_port, $client, $input);
> 
> use IO::Socket::INET;
> 
> $server_port = 33000;
> 
> $server = IO::Socket::INET->new (LocalPort => $server_port,
>                                  Type      => SOCK_STREAM,
>                                  Reuse     => 1,
>                                  Listen    => 10 )   #or SOMAXCONN
>         or die "Couldn't be a TCP server on port
> $server_port:  $! \n";
> 
> while ($client = $server->accept()) {
>         my $n = sysread($client,$input,1000);
>         print "$input\n" ;

Well, you're only calling sysread() once for each client and then going back
to call accept() to get the next client connection. You need to read in a
loop if you want to get all the client's input:

   print while <$client>;

But, your server can only handle one client at a time. The kernel will queue
up additional clients (up to 10) as they connect, but they will be blocked
until the server gets around to them. You should investigate a forking
server. There's a (rather lengthy) example in perldoc perlipc.

>         next;  #THIS DOESN'T HELP
>         }

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

Reply via email to