PageRenderTime 80ms CodeModel.GetById 71ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/otp.net/OtpTest/Test.cs

http://github.com/gebi/jungerl
C# | 84 lines | 68 code | 15 blank | 1 comment | 4 complexity | 8cacc39fa948be6ef0e2e462c42322a5 MD5 | raw file
 1using System;
 2
 3namespace Otp
 4{
 5    public class Test
 6    {
 7        static public void Main(String[] args)
 8        {
 9            System.Console.Out.WriteLine("Otp test...");
10
11            if (args.Length < 1)
12            {
13                System.Console.Out.WriteLine("Usage: Otp sname\n  where sname is" +
14                    "the short name of the Erlang node");
15                return;
16            }
17
18            OtpNode.useShortNames = true;
19
20            String  host   = System.Net.Dns.GetHostName();
21            String  user   = Environment.UserName;
22            OtpNode node   = new OtpNode(user + "@" + host);
23            String  remote = (args[0].Contains("@")) ? args[0] : remote = args[0] + "@" + host;
24            OtpMbox mbox   = null;
25
26            System.Console.Out.WriteLine("This node is: {0} (cookie='{1}'). Remote: {2}",
27                node.node(), node.cookie(), remote);
28            
29            //bool ok = node.ping(remote, 1000*300);
30
31            OtpCookedConnection conn = node.getConnection(remote);
32
33            try
34            {
35                if (conn != null)
36                    System.Console.Out.WriteLine("   successfully pinged node " + remote + "\n");
37                else
38                    throw new System.Exception("Could not ping node: " + remote);
39
40                conn.traceLevel = 1;
41
42                mbox = node.createMbox();
43                mbox.registerName("server");
44
45                mbox.sendRPC(conn.peer.node(), "lists", "reverse", new Erlang.List(new Erlang.String("Hello world!")));
46				Erlang.Object reply = mbox.receiveRPC(5000);
47                System.Console.Out.WriteLine("<= " + reply.ToString());
48
49                {
50                    Erlang.List rpcArgs = new Erlang.List(
51                        new Erlang.Object[] {
52                            mbox.self(),
53                            new Erlang.Tuple(
54                                new Erlang.Object[] {
55                                    new Erlang.Atom("table"), new Erlang.Atom("test"), new Erlang.Atom("simple")
56                                }
57                            )
58                        }
59                    );
60
61                    mbox.sendRPC(conn.peer.node(), "mnesia_subscr", "subscribe", rpcArgs);
62				    reply = mbox.receiveRPC(5000);
63                    System.Console.Out.WriteLine("<= " + reply.ToString());
64                }
65
66                while (true)
67                {
68                    Erlang.Object msg = mbox.receive();
69                    System.Console.Out.WriteLine("IN msg: " + msg.ToString() + "\n");
70                }
71            }
72            catch (System.Exception e)
73            {
74                System.Console.Out.WriteLine("Error: " + e.ToString());
75            }
76            finally
77            {
78                node.closeMbox(mbox);
79            }
80
81            node.close();
82        }
83    }
84}