Close socket when lost connection.