> 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" ;
> next; #THIS DOESN'T HELP
> }
Eventually what you are going to need to have is a forking server that
spawns child processes for each client connection. Other posters already
mentioned how you can fix your loop to handle more than one 'message' coming
from a client.
start off by reading:
perldoc -f fork
perldoc perlipc
perldoc IO::SOCKET
so you will something like:
while ($new_cli = $sock->accept()) {
if ($pid == fork) {
#child is now dealing with the ne client
#exit when this child is done and go to next.
exit;
} else {
#read from the new sock here
#close when done
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]