Close socket correctement