Check that socket object exists before calling subscribe

Fixes #724
Fixes #626
Merge branch 'master' into development