Could you move both, the get host and port inside your if? No need to get it if we are not using it