while ($client = $server->accept()) { # first get a connection while (<$client>) { # read each line from it print FILE $_; # and write the data to our file } close $client; # then close the connection } # repeat