in reply to Getting Client to Disconnect

The single model when it gets the "disconnect" string should shut down the client and restart in a loop within the server_run_type function.

As you currently have it, the server will wait for a new client connection after having closed the old connection. This is due to the loop

while ( my $client = $server->accept( ) ) { ... }

If you want it to return from sub server_run_single after the first connection has been closed, just don't use a loop, but rather simply

my $client = $server->accept();

Replies are listed 'Best First'.
Re^2: Getting Client to Disconnect
by gokuraku (Monk) on Dec 18, 2007 at 12:30 UTC
    Ah...I was hoping it could exit the while loop so I could start multiple servers over time. My expectation was the server may need to wait for clients, hence my use of the while here, but this was not working with close($client) since it just stayed in the loop.

    Gave this a try and my working code now looks like:

    sub server_run_single() { my ($server,$keepAlive,$i,$loop,$verbose) = @_; my $d_count = 0; my $result = 0; print "Running Server loop $i of $loop.\n" if $verbose; # accept and process connections my $client = $server->accept( ); $clientCount = &add_Clientcount($verbose); print "Connected - " . &id_client($client) . "\n"; while ( defined (my $data_recv = <$client>) ) { if ($data_recv =~ m/discon/) { $clientCount = &subt_Clientcount($verbose); # Get out of this loop close($client); } print STDOUT $data_recv if $verbose; print $client "You said - $data_recv\n" if $verbose; } print "Exiting loop $i of $loop.\n" if $verbose; return $result; }

    Thanks!