wrapping socket with if