Just had this issue myself then eventually found out that the problem was that the server I was trying to connect to was down. Hadn't got as far as putting error checking in!

Hopefully that helps anyone else who stumbles on this thread via google.