in reply to socket problem

You can simply change your die to next, so that instead of quit the program entirely, it will just skip this ill-fated iteration.