Take into account the port setting when connect via gateway

This is needed when you deploy to the gateway server with a different port number.