/// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> /// <exception cref="System.IO.IOException"></exception> public EchoClientTest() { // // Create a portmap client object, which can then be used to contact // the local ONC/RPC ServerTest test server. // OncRpcClient client = new OncRpcTcpClient(IPAddress.Loopback, unchecked ((int)(0x49679)), 1, 0); // // Ping the test server... // System.Console.Out.Write("pinging test server: "); try { client.call(0, XdrVoid.XDR_VOID, XdrVoid.XDR_VOID ); } catch (OncRpcException e) { System.Console.Out.WriteLine("method call failed unexpectedly:"); System.Console.Out.WriteLine(e.StackTrace); System.Environment.Exit(1); } System.Console.Out.WriteLine("test server is alive."); // // Now check the echo RPC call... // string[] messages = new string[] { "Open Source", "is not yet", "another buzzword." }; checkEcho(client, messages); // // Now test AUTH_UNIX authentication. First start with an // invalid credential... // OncRpcClientAuth auth = new OncRpcClientAuthUnix ("marvin", 0, 0, new int[0]); client.setAuth(auth); System.Console.Out.Write("checking AUTH_UNIX with invalid credential: "); try { client.call(0, XdrVoid.XDR_VOID, XdrVoid.XDR_VOID ); } catch (OncRpcAuthenticationException ae) { if (ae.getAuthStatus() != OncRpcAuthStatus.ONCRPC_AUTH_BADCRED) { System.Console.Out.WriteLine("received wrong authentication exception with status of " + ae.getAuthStatus()); System.Console.Out.WriteLine(ae.StackTrace); System.Environment.Exit(1); } } catch (OncRpcException e) { System.Console.Out.WriteLine("method call failed unexpectedly:"); System.Console.Out.WriteLine(e.StackTrace); System.Environment.Exit(1); } System.Console.Out.WriteLine("passed."); auth = new OncRpcClientAuthUnix("marvin", 42, 815, new int[0]); client.setAuth(auth); messages = new string[] { "AUTH_UNIX", "is like", "*NO* authentication", "--", "it" , "uses", "*NO CRYPTOGRAPHY*", "for securing", "ONC/RPC messages" }; checkEcho(client, messages); client.setAuth(null); // // Release resources bound by ONC/RPC client object as soon as possible // so might help the garbage wo/man. Yeah, this is now a political // correct comment. // client.close(); client = null; }
/// <exception cref="org.acplt.oncrpc.OncRpcException"></exception> /// <exception cref="System.IO.IOException"></exception> public ServerTest() { // // Flag to signal shut down of the server. // // // Shorthand credential use counter. // // // // OncRpcUdpServerTransport udpTrans = new OncRpcUdpServerTransport (this, 55555, unchecked ((int)(0x49679)), 1, 8192); OncRpcTcpServerTransport tcpTrans = new OncRpcTcpServerTransport (this, 55555, unchecked ((int)(0x49679)), 1, 8192); //java.lang.Runtime.getRuntime().addShutdownHook(new tests.org.acplt.oncrpc.ServerTest.ShutdownHookThread // (this, this)); udpTrans.register(); tcpTrans.register(); System.Console.Out.WriteLine("Server started."); tcpTrans.listen(); udpTrans.listen(); // // Reality Check: open a connection to the TCP/IP server socket // waiting for incoming connection, thus testing proper shutdown // behaviour later... // OncRpcTcpClient client = new OncRpcTcpClient(IPAddress.Loopback, unchecked ((int)(0x49679)), 1, 0); // // Now wait for the shutdown to become signalled... Note that // a simple call to wait() without the outer loop would not be // sufficient as we might get spurious wake-ups due to // interruptions. // for (; ;) { lock (leaveTheStage) { try { Monitor.Wait(leaveTheStage); break; } catch (System.Exception) { } } } Console.Out.WriteLine("Server shutting down..."); // // Unregister TCP-based transport. Then close it. This will // also automatically bring down the threads handling individual // TCP transport connections. // tcpTrans.unregister(); tcpTrans.Close(); // // Unregister UDP-based transport. Then close it. This will // automatically bring down the thread which handles the // UDP transport. // udpTrans.unregister(); udpTrans.Close(); Console.Out.WriteLine("Server shut down."); }