added reconnection logic for socket if connection is lost