close socket properly