Split socket operations into separate functions, just in case there might be more work involved in the future.