Check whether socket is still open

This supersedes #2