reconnect logic for websockets