added isConnected to connectSockets and added error management to detect disconnection