New method detectServerAddress() added which should rewrite your code ito.