Check that socket object exists before calling subscribe

Fixes #724
Fixes #626
Merge pull request #726 from freshvolk/master

Check that socket object exists before calling subscribe