/// <summary> /// Register the TCP/IP port where this server transport waits for incoming /// requests with the ONC/RPC portmapper. /// </summary> /// <remarks> /// Register the TCP/IP port where this server transport waits for incoming /// requests with the ONC/RPC portmapper. /// </remarks> /// <exception cref="org.acplt.oncrpc.OncRpcException"> /// if the portmapper could not be contacted /// successfully of if the portmapper rejected port registration(s). /// </exception> public override void register() { try { org.acplt.oncrpc.OncRpcPortmapClient portmapper = new org.acplt.oncrpc.OncRpcPortmapClient (IPAddress.Loopback); 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, org.acplt.oncrpc.OncRpcProtocols .ONCRPC_TCP, port)) { throw (new org.acplt.oncrpc.OncRpcException(org.acplt.oncrpc.OncRpcException.RPC_CANNOTREGISTER )); } } } catch (System.IO.IOException) { throw (new org.acplt.oncrpc.OncRpcException(org.acplt.oncrpc.OncRpcException.RPC_FAILED )); } }
/// <summary> /// Unregisters the port where this server transport waits for incoming /// requests from the ONC/RPC portmapper. /// </summary> /// <remarks> /// Unregisters the port where this server transport waits for incoming /// requests from the ONC/RPC portmapper. /// <p>Note that due to the way Sun decided to implement its ONC/RPC /// portmapper process, deregistering one server transports causes all /// entries for the same program and version to be removed, regardless /// of the protocol (UDP/IP or TCP/IP) used. Sigh. /// </remarks> /// <exception cref="org.acplt.oncrpc.OncRpcException"> /// with a reason of /// <see cref="org.acplt.oncrpc.OncRpcException.RPC_FAILED">OncRpcException.RPC_FAILED /// </see> /// if /// the portmapper could not be contacted successfully. Note that /// it is not considered an error to remove a non-existing entry from /// the portmapper. /// </exception> public virtual void unregister() { try { org.acplt.oncrpc.OncRpcPortmapClient portmapper = new org.acplt.oncrpc.OncRpcPortmapClient (IPAddress.Loopback); int size = info.Length; for (int idx = 0; idx < size; ++idx) { portmapper.unsetPort(info[idx].program, info[idx].version); } } catch (System.IO.IOException) { throw (new OncRpcException(OncRpcException.RPC_FAILED )); } }
/// <summary>Constructs an <code>OncRpcClient</code> object (the generic part).</summary> /// <remarks> /// Constructs an <code>OncRpcClient</code> object (the generic part). If /// no port number is given (that is, <code>port</code> is <code>0</code>), /// then a port lookup using the portmapper at <code>host</code> is done. /// </remarks> /// <param name="host">Host address where the desired ONC/RPC server resides.</param> /// <param name="program">Program number of the desired ONC/RPC server.</param> /// <param name="version">Version number of the desired ONC/RPC server.</param> /// <param name="protocol"> /// /// <see cref="OncRpcProtocols">Protocol</see> /// to be used for /// ONC/RPC calls. This information is necessary, so port lookups through /// the portmapper can be done. /// </param> /// <exception cref="OncRpcException">if an ONC/RPC error occurs.</exception> /// <exception cref="System.IO.IOException">if an I/O error occurs.</exception> /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> internal OncRpcClient(IPAddress host, int program, int version, int port , int protocol) { // // Set up the basics... // this.host = host; this.program = program; this.version = version; // // Initialize the message identifier with some more-or-less random // value. // long seed = DateTime.Now.Ticks; xid = ((int)seed) ^ ((int)((seed) >> (32 & 0x1f))); // // If the port number of the ONC/RPC server to contact is not yet // known, try to find it out. For this we need to contact the portmap // process at the given host and ask it for the desired program. // // In case of tunneling through the HTTP protocol, we accept a port // number of zero and do not resolve it. This task is left up to // the other end of the HTTP tunnel (at the web server). // if ((port == 0) && (protocol != org.acplt.oncrpc.OncRpcProtocols.ONCRPC_HTTP)) { org.acplt.oncrpc.OncRpcPortmapClient portmap = new org.acplt.oncrpc.OncRpcPortmapClient (host); try { port = portmap.getPort(program, version, protocol); } finally { portmap.close(); } } this.port = port; }
/// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> /// <exception cref="System.IO.IOException"></exception> public PortmapGetPortTest() { // // Create a portmap client object, which can then be used to contact // a local or remote ONC/RPC portmap process. In this test we contact // the local portmapper. // org.acplt.oncrpc.OncRpcPortmapClient portmap = new org.acplt.oncrpc.OncRpcPortmapClient (java.net.InetAddress.getByName("localhost")); //portmap.setRetransmissionMode(OncRpcUdpRetransmissionMode.FIXED); //portmap.setRetransmissionTimeout(3*1000); // // Ping the portmapper... // System.Console.Out.Write("pinging portmapper: "); try { portmap.ping(); } catch (org.acplt.oncrpc.OncRpcException e) { System.Console.Out.WriteLine("method call failed unexpectedly:"); Sharpen.Runtime.printStackTrace(e, System.Console.Out); System.Environment.Exit(1); } System.Console.Out.WriteLine("portmapper is alive."); // // Ask for a non-existent ONC/RPC server. // int port; System.Console.Out.Write("getPort() for non-existing program: "); try { port = portmap.getPort(1, 1, org.acplt.oncrpc.OncRpcProtocols.ONCRPC_UDP); System.Console.Out.WriteLine("method call failed (program found)."); } catch (org.acplt.oncrpc.OncRpcException e) { if (e.getReason() != org.acplt.oncrpc.OncRpcException.RPC_PROGNOTREGISTERED) { System.Console.Out.WriteLine("method call failed unexpectedly:"); Sharpen.Runtime.printStackTrace(e, System.Console.Out); System.Environment.Exit(10); } System.Console.Out.WriteLine("succeeded (RPC_PROGNOTREGISTERED)."); } // // Register dummy ONC/RPC server. // System.Console.Out.Write("setPort() dummy server identification: "); try { portmap.setPort(1, 42, org.acplt.oncrpc.OncRpcProtocols.ONCRPC_UDP, 65535); } catch (org.acplt.oncrpc.OncRpcException e) { System.Console.Out.WriteLine("method call failed unexpectedly:"); Sharpen.Runtime.printStackTrace(e, System.Console.Out); System.Environment.Exit(12); } System.Console.Out.WriteLine("succeeded."); // // Now dump the current list of registered servers. // org.acplt.oncrpc.OncRpcServerIdent[] list = null; int i; bool found = false; System.Console.Out.Write("listServers(): "); try { list = portmap.listServers(); } catch (org.acplt.oncrpc.OncRpcException e) { System.Console.Out.WriteLine("method call failed unexpectedly:"); Sharpen.Runtime.printStackTrace(e, System.Console.Out); System.Environment.Exit(20); } System.Console.Out.WriteLine("succeeded."); for (i = 0; i < list.Length; ++i) { if ((list[i].program == 1) && (list[i].version == 42) && (list[i].protocol == org.acplt.oncrpc.OncRpcProtocols .ONCRPC_UDP) && (list[i].port == 65535)) { found = true; } System.Console.Out.WriteLine(" " + list[i].program + " " + list[i].version + " " + list[i].protocol + " " + list[i].port); } if (!found) { System.Console.Out.WriteLine("registered dummy server ident not found."); System.Environment.Exit(22); } // // Deregister dummy ONC/RPC server. // System.Console.Out.Write("unsetPort() dummy server identification: "); try { portmap.unsetPort(1, 42); } catch (org.acplt.oncrpc.OncRpcException e) { System.Console.Out.WriteLine("method call failed unexpectedly:"); Sharpen.Runtime.printStackTrace(e, System.Console.Out); System.Environment.Exit(12); } System.Console.Out.WriteLine("succeeded."); // // Now dump again the current list of registered servers. // found = false; list = null; System.Console.Out.Write("listServers(): "); try { list = portmap.listServers(); } catch (org.acplt.oncrpc.OncRpcException e) { System.Console.Out.WriteLine("method call failed unexpectedly:"); Sharpen.Runtime.printStackTrace(e, System.Console.Out); System.Environment.Exit(20); } System.Console.Out.WriteLine("succeeded."); for (i = 0; i < list.Length; ++i) { if ((list[i].program == 1) && (list[i].version == 42) && (list[i].protocol == org.acplt.oncrpc.OncRpcProtocols .ONCRPC_UDP) && (list[i].port == 65535)) { found = true; break; } } if (found) { System.Console.Out.WriteLine("registered dummy server ident still found after deregistering." ); System.Environment.Exit(22); } // // Release resources bound by portmap client object as soon as possible // so might help the garbage wo/man. Yeah, this is now a political // correct comment. // portmap.close(); portmap = null; }