Modify TCP blocking connection and add mutexes