Added socket error catching to prevent segfault after receive