Support UDP input. Also fix some issues with socket closing.