pulled in the socket code for future changes to make it more simple and less generic