Use try-with-resources to get localport