PageRenderTime 100ms CodeModel.GetById 93ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

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