check for socket before close fixes #216
Merge pull request #217 from JoshMcKin/check_for_socket

check for socket before close fixes #216