private OncRpcClient createRpcClient() throws OncRpcException, IOException { // invoke portmap OncRpcPortmapClient portmap = new OncRpcPortmapClient(host); int port; try { port = portmap.getPort( NFS_PROGRAM, NFS_VERSION, protocol == Protocol.UDP ? OncRpcProtocols.ONCRPC_UDP : OncRpcProtocols.ONCRPC_TCP); } finally { portmap.close(); } // create the client // We create the client with a buffer with lenght equals witn MAX_DATA + // 424 ( max header length) OncRpcClient client = null; if (protocol == Protocol.UDP) { client = new OncRpcUdpClient(host, NFS_PROGRAM, NFS_VERSION, port, MAX_DATA + HEADER_DATA); } else if (protocol == Protocol.TCP) { client = new OncRpcTcpClient(host, NFS_PROGRAM, NFS_VERSION, port, MAX_DATA + HEADER_DATA); } else { // TODO Do something } client.setTimeout(10000); if (uid != -1 && gid != -1) { client.setAuth(new OncRpcClientAuthUnix("test", uid, gid)); } return client; }
/** * Register the TCP/IP port where this server transport waits for incoming requests with the * ONC/RPC portmapper. * * @throws OncRpcException if the portmapper could not be contacted successfully of if the * portmapper rejected port registration(s). */ public void register() throws OncRpcException { try { OncRpcPortmapClient portmapper = new OncRpcPortmapClient(InetAddress.getByName("127.0.0.1")); int size = info.length; for (int idx = 0; idx < size; ++idx) { // // Try to register the port for our transport with the local ONC/RPC // portmapper. If this fails, bail out with an exception. // if (!portmapper.setPort( info[idx].program, info[idx].version, OncRpcProtocols.ONCRPC_TCP, port)) { throw (new OncRpcException(OncRpcException.RPC_CANNOTREGISTER)); } } } catch (IOException e) { throw (new OncRpcException(OncRpcException.RPC_FAILED)); } }