Separated socket code into a new file.