reformat header and close socket in server