Open and close socket