PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/otp.net/Otp/Test.cs

https://github.com/bmizerany/jungerl
C# | 68 lines | 55 code | 13 blank | 0 comment | 2 complexity | e1991af279e275511c691d6c2bb0792f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, AGPL-1.0
  1. using System;
  2. namespace Otp
  3. {
  4. public class Test
  5. {
  6. static public void Main(String[] args)
  7. {
  8. System.Console.Out.WriteLine("Otp test...");
  9. if (args.Length < 1)
  10. {
  11. System.Console.Out.WriteLine("Usage: Otp sname\n where sname is"+
  12. "the short name of the Erlang node");
  13. return;
  14. }
  15. String host = System.Net.Dns.GetHostName();
  16. String remote = args[0]+"@"+host;
  17. OtpNode node = new OtpNode("q@"+host);
  18. System.Console.Out.WriteLine("This node is called {0} and is using cookie='{1}'.",
  19. node.node(), node.cookie());
  20. bool ok=false;
  21. ok = node.ping(remote, 1000);
  22. if (ok)
  23. System.Console.Out.WriteLine(" successfully pinged node "+remote+"\n");
  24. else
  25. System.Console.Out.WriteLine(" could not ping node "+remote+"\n");
  26. OtpMbox mbox = null;
  27. try
  28. {
  29. mbox = node.createMbox();
  30. Erlang.Object[] rpc = new Erlang.Object[2];
  31. Erlang.Object[] call = new Erlang.Object[5];
  32. call[0] = new Erlang.Atom("call");
  33. call[1] = new Erlang.Atom("lists");
  34. call[2] = new Erlang.Atom("reverse");
  35. call[3] = new Erlang.List(new Erlang.List("Hello Erlang world!"));
  36. call[4] = mbox.self();
  37. rpc[0] = mbox.self();
  38. rpc[1] = new Erlang.Tuple(call);
  39. Erlang.Tuple rpcTuple = new Erlang.Tuple(rpc);
  40. System.Console.Out.WriteLine("=> "+rpcTuple.ToString());
  41. mbox.send("rex", remote, rpcTuple);
  42. Erlang.Object reply = mbox.receive(1000);
  43. System.Console.Out.WriteLine("<= "+reply.ToString());
  44. }
  45. catch (System.Exception)
  46. {
  47. }
  48. finally
  49. {
  50. node.closeMbox(mbox);
  51. }
  52. node.close();
  53. }
  54. }
  55. }