finalized socket_utils.py