/// <summary> /// Register the UDP/IP port where this server transport waits for incoming /// requests with the ONC/RPC portmapper. /// </summary> /// <remarks> /// Register the UDP/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. /// </exception> public override void register() { try { OncRpcPortmapClient portmapper = new 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, OncRpcProtocols .ONCRPC_UDP, port)) { throw (new OncRpcException(OncRpcException.RPC_CANNOTREGISTER )); } } } catch (IOException) { throw (new OncRpcException(OncRpcException.RPC_FAILED )); } }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> /// <exception cref="java.net.UnknownHostException"></exception> public EmbeddedPortmapTest() { // // Diagnostic: Is a portmapper already running? // Console.Out.Write("Checking for portmap service: "); bool externalPortmap = OncRpcEmbeddedPortmap.isPortmapRunning (); if (externalPortmap) { Console.Out.WriteLine("A portmap service is already running."); } else { Console.Out.WriteLine("No portmap service available."); } // // Create embedded portmap service and check whether is has sprung // into action. // Console.Out.Write("Creating embedded portmap instance: "); try { epm = new OncRpcEmbeddedPortmap(); } catch (System.IO.IOException e) { Console.Out.WriteLine("ERROR: failed:"); Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e.StackTrace); } catch (OncRpcException e) { Console.Out.WriteLine("ERROR: failed:"); Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e.StackTrace); } if (!epm.embeddedPortmapInUse()) { Console.Out.Write("embedded service not used: "); } else { Console.Out.Write("embedded service started: "); } if (epm.embeddedPortmapInUse() == externalPortmap) { Console.Out.WriteLine("ERROR: no service available or both."); return; } Console.Out.WriteLine("Passed."); // // Now register dummy ONC/RPC program. Note that the embedded // portmap service must not automatically spin down when deregistering // the non-existing dummy program. // OncRpcPortmapClient pmap = new OncRpcPortmapClient (IPAddress.Loopback); Console.Out.Write("Deregistering non-existing program: "); pmap.unsetPort(12345678, 42); Console.Out.WriteLine("Passed."); Console.Out.Write("Registering dummy program: "); pmap.setPort(12345678, 42, OncRpcProtocols.ONCRPC_TCP, 42); Console.Out.WriteLine("Passed."); Console.Out.WriteLine("Press any key to continue..."); string s = Console.In.ReadLine(); Console.Out.Write("Deregistering dummy program: "); pmap.unsetPort(12345678, 42); Console.Out.WriteLine("Passed."); // This to match the sleep in the embedded portmap to make sure we return // our message to the client before shutting down the socket. This should // be fixed to work with synchronization rather than time, but it's what I // got done for the time being. Thread.Sleep(1000); Console.Out.WriteLine("Press any key to continue..."); s = Console.In.ReadLine(); // // Check that an embedded portmap service spins down properly if it // was started within this test. // if (OncRpcEmbeddedPortmap.isPortmapRunning() && !externalPortmap) { Console.Out.WriteLine("ERROR: embedded portmap service still running."); } }