close socket function implemented