move sleep out of runOnce, added interrupt handler to close socket