Check that socket object exists before calling subscribe

Fixes #724
Fixes #626