Added check for NULL in socket creation