Add more resilient TCP listening function.