Try to refresh the socket when sending a message fails

Should address #20  (Could not reproduce the bug the user is seeing but this should work)

`[Errno 9] Bad file descriptor` happens when trying to write to a socket that has been closed. This change try to use a new socket when this happens.