Move socket code to own module