Reorganize sockets and mutex on stopped boolean

Mutex on stopped boolean is needed to avoid a conflict between routines and connect & disconnect functions