Check used port, fix #985.