Move port management into a package for sharing with test server