code: public static int queryPortFromPortMap(int program, int version, String serverIP) throws IOException {
          GetPortResponse response = null;
          GetPortRequest request = new GetPortRequest(program, version);
          for (int i = 0; i < _maxRetry; ++i) {
              try {
                  Xdr portmapXdr = new Xdr(PORTMAP_MAX_REQUEST_SIZE);
                  request.marshalling(portmapXdr);
  
                  Xdr reply = NetMgr.getInstance().sendAndWait(serverIP, PMAP_PORT, _usePrivilegedPort, portmapXdr,
                          PORTMAP_RPC_TIMEOUT);
  
                  response = new GetPortResponse();
                  response.unmarshalling(reply);
              } catch (RpcException e) {
                  handleRpcException(e, i, serverIP);
              }
          }
  
          int port = response.getPort();
          if (port == 0) { // A port value of zeros means the program has not been
                           // registered.
              String msg = String.format("No registry entry for program: %s, version: %s, serverIP: %s", program, version,
                      serverIP);
              throw new IOException(msg);
          }
          return port;
      }
docs: Given program and version of a service, query its tcp port number
  
  @param program
  The program number, used to identify it for RPC calls.
  @param version
  The program version number, used to identify it for RPC calls.
  @param serverIP
  The server IP address.
  @return The port number for the program.