Working code to turn sockets on and off