Apply patch from bug 24104 by John Du Hart for allowing custom port.