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

Language C# Lines 85
MD5 Hash 8cacc39fa948be6ef0e2e462c42322a5
Repository git://github.com/gebi/jungerl.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;

namespace Otp
{
    public class Test
    {
        static public void Main(String[] args)
        {
            System.Console.Out.WriteLine("Otp test...");

            if (args.Length < 1)
            {
                System.Console.Out.WriteLine("Usage: Otp sname\n  where sname is" +
                    "the short name of the Erlang node");
                return;
            }

            OtpNode.useShortNames = true;

            String  host   = System.Net.Dns.GetHostName();
            String  user   = Environment.UserName;
            OtpNode node   = new OtpNode(user + "@" + host);
            String  remote = (args[0].Contains("@")) ? args[0] : remote = args[0] + "@" + host;
            OtpMbox mbox   = null;

            System.Console.Out.WriteLine("This node is: {0} (cookie='{1}'). Remote: {2}",
                node.node(), node.cookie(), remote);
            
            //bool ok = node.ping(remote, 1000*300);

            OtpCookedConnection conn = node.getConnection(remote);

            try
            {
                if (conn != null)
                    System.Console.Out.WriteLine("   successfully pinged node " + remote + "\n");
                else
                    throw new System.Exception("Could not ping node: " + remote);

                conn.traceLevel = 1;

                mbox = node.createMbox();
                mbox.registerName("server");

                mbox.sendRPC(conn.peer.node(), "lists", "reverse", new Erlang.List(new Erlang.String("Hello world!")));
				Erlang.Object reply = mbox.receiveRPC(5000);
                System.Console.Out.WriteLine("<= " + reply.ToString());

                {
                    Erlang.List rpcArgs = new Erlang.List(
                        new Erlang.Object[] {
                            mbox.self(),
                            new Erlang.Tuple(
                                new Erlang.Object[] {
                                    new Erlang.Atom("table"), new Erlang.Atom("test"), new Erlang.Atom("simple")
                                }
                            )
                        }
                    );

                    mbox.sendRPC(conn.peer.node(), "mnesia_subscr", "subscribe", rpcArgs);
				    reply = mbox.receiveRPC(5000);
                    System.Console.Out.WriteLine("<= " + reply.ToString());
                }

                while (true)
                {
                    Erlang.Object msg = mbox.receive();
                    System.Console.Out.WriteLine("IN msg: " + msg.ToString() + "\n");
                }
            }
            catch (System.Exception e)
            {
                System.Console.Out.WriteLine("Error: " + e.ToString());
            }
            finally
            {
                node.closeMbox(mbox);
            }

            node.close();
        }
    }
}
Back to Top