check port is valid

Fixes #2480