rpcCall() public method

public rpcCall ( string node, Erlang mod, Erlang fun, Erlang args ) : Otp.Erlang.Object
node string
mod Erlang
fun Erlang
args Erlang
return Otp.Erlang.Object
示例#1
0
文件: Test.cs 项目: yonglehou/otp.net
        static public void Main(String[] args)
        {
            System.Console.Out.WriteLine("Otp test...");

            string cookie   = OtpNode.defaultCookie;
            string host     = System.Net.Dns.GetHostName();
            string remote   = (args[0].IndexOf('@') < 0) ? args[0] + "@" + host : args[0];
            string nodename = Environment.UserName + "123@" + host;

            AbstractConnection.traceLevel = OtpTrace.Type.sendThreshold;

            if (args.Length < 1)
            {
                System.Console.Out.WriteLine(
                    "Usage: {0} remotenode [cookie] [-notrace]\n" +
                    "    nodename  - is the name of the remote Erlang node\n" +
                    "    cookie    - is the optional cookie string to use\n" +
                    "    -name     - this node name\n" +
                    "    -wire     - wire-level tracing\n" +
                    "    -notrace  - disable debug trace\n",
                    Environment.GetCommandLineArgs()[0]);
                return;
            }
            else if (args.Length > 1 && args[1][0] != '-')
            {
                cookie = args[1].ToString();
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Equals("-wire"))
                {
                    AbstractConnection.traceLevel = OtpTrace.Type.wireThreshold;
                }
                else if (args[i].Equals("-notrace"))
                {
                    AbstractConnection.traceLevel = OtpTrace.Type.defaultLevel;
                }
                else if (args[i].Equals("-name") && i + 1 < args.Length)
                {
                    nodename = args[i++ + 1];
                    if (nodename.IndexOf('@') < 0)
                    {
                        nodename += '@' + host;
                    }
                }
            }

            OtpNode node = new OtpNode(false, nodename, cookie, true);

            System.Console.Out.WriteLine("This node is called {0} and is using cookie='{1}'.",
                                         node.node(), node.cookie());

            OtpCookedConnection.ConnectTimeout = 2000;
            OtpCookedConnection conn = node.connection(remote);

            conn.OnReadWrite += OnReadWrite;

            if (conn == null)
            {
                Console.WriteLine("Can't connect to node " + remote);
                return;
            }

            // If using short names or IP address as the host part of the node name,
            // get the short name of the peer.
            remote = conn.peer.node();

            System.Console.Out.WriteLine("   successfully connected to node " + remote + "\n");

            OtpMbox mbox = null;

            try
            {
                mbox = node.createMbox();

                {
                    Otp.Erlang.Object reply = mbox.rpcCall(
                        remote, "lists", "reverse", new Otp.Erlang.List("Abcdef!"));
                    System.Console.Out.WriteLine("<= [REPLY1]:" + (reply == null ? "null" : reply.ToString()));
                }

                {
                    Otp.Erlang.Object reply = mbox.rpcCall(
                        remote, "global", "register_name",
                        new Otp.Erlang.List(new Otp.Erlang.Atom("me"), mbox.self()));

                    System.Console.Out.WriteLine("<= [REPLY2]:" + (reply == null ? "null" : reply.ToString()));
                }

                {
                    Otp.Erlang.Object reply = mbox.rpcCall(remote, "global", "register_name", new Otp.Erlang.List(new Otp.Erlang.Atom("me"), mbox.self()), 5000);
                    System.Console.Out.WriteLine("<= [REPLY3]:" + (reply == null ? "null" : reply.ToString()));
                }

                {
                    Otp.Erlang.Object reply = mbox.rpcCall(
                        remote, "io", "format",
                        new Otp.Erlang.List(
                            "Test: ~w -> ~w\n",
                            new Otp.Erlang.List(mbox.self(), new Otp.Erlang.Atom("ok"))
                            ));

                    System.Console.Out.WriteLine("<= [REPLY4]:" + (reply == null ? "null" : reply.ToString()));
                }

                while (true)
                {
                    Otp.Erlang.Object msg = mbox.receive();
                    if (msg is Otp.Erlang.Tuple)
                    {
                        Otp.Erlang.Tuple m = msg as Otp.Erlang.Tuple;
                        if (m.arity() == 2 && m.elementAt(0) is Otp.Erlang.Pid)
                        {
                            mbox.send(m.elementAt(0) as Otp.Erlang.Pid, m.elementAt(1));
                        }
                    }
                    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();
        }
示例#2
0
        private void GetList(OtpMbox mbox, Action<IEnumerable<Tuple<String, object>>> handler)
        {
            Otp.Erlang.Object reply = mbox.rpcCall(
                remote, "servant", "get_confirmations",
                new Otp.Erlang.List());

            Erlang.Object okPat = Erlang.Object.Format("{ok, List}");
            Erlang.Object itemPat = Erlang.Object.Format("{Text,Code}");
            Erlang.VarBind binding;
            if (okPat.match(reply, (binding = new Otp.Erlang.VarBind())))
            {
                Erlang.List list = binding.find("List") as Erlang.List;
                handler(ListToMenuItems(list));
            }
            else
            {
                WriteLine("Bad reply on getList {0}", reply.ToString());
            }
        }
示例#3
0
 private void SendDo(OtpMbox mbox, Erlang.Object code)
 {
     Otp.Erlang.Object reply = mbox.rpcCall(
         remote, "servant", "process_confirmation",
         new Otp.Erlang.List(code));
     WriteLine("Do reply: {0}", reply);
 }
示例#4
0
文件: Test1.cs 项目: tonyrog/jungerl
        static public void Main(String[] args)
        {
            {
                Erlang.Object obj1 = Erlang.Object.Format("{a, b, 10, 2.0}");
                Erlang.Object obj2 = Erlang.Object.Format("{a, [b, 1, 2.0, \"abc\"], {1, 2}}");
            }

            System.Console.Out.WriteLine("Otp test...");

            string cookie = OtpNode.defaultCookie;

            AbstractConnection.traceLevel = OtpTrace.Type.sendThreshold;

            if (args.Length < 1)
            {
                System.Console.Out.WriteLine(
                    "Usage: {0} nodename [cookie] [-notrace]\n" +
                    "    nodename  - is the name of the remote Erlang node\n" +
                    "    cookie    - is the optional cookie string to use\n" +
                    "    -notrace  - disable debug trace\n",
                    Environment.GetCommandLineArgs()[0]);
                return;
            }
            else if (args.Length > 1)
            {
                cookie = args[1].ToString();
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Equals("-notrace"))
                {
                    AbstractConnection.traceLevel = OtpTrace.Type.defaultLevel;
                    break;
                }
            }


            String host   = System.Net.Dns.GetHostName();
            String remote = (args[0].IndexOf('@') < 0) ? args[0] + "@" + host : args[0];

            OtpNode node = new OtpNode(false, Environment.UserName + "123@" + host, cookie, true);

            System.Console.Out.WriteLine("This node is called {0} and is using cookie='{1}'.",
                                         node.node(), node.cookie());

            bool ok = node.ping(remote, 1000);

            if (!ok)
            {
                Console.WriteLine("Can't connect to node " + remote);
                return;
            }

            // If using short names, get the short name of the peer.
            remote = node.connection(remote).peer.node();

            if (remote != null)
            {
                System.Console.Out.WriteLine("   successfully pinged node " + remote + "\n");
            }
            else
            {
                System.Console.Out.WriteLine("   could not ping node " + remote + "\n");
            }

            OtpMbox mbox = null;

            try
            {
                mbox = node.createMbox();

                {
                    Otp.Erlang.Object reply = mbox.rpcCall(
                        remote, "lists", "reverse", new Otp.Erlang.List("Abcdef!"));
                    System.Console.Out.WriteLine("<= [REPLY1]:" + (reply == null ? "null" : reply.ToString()));
                }

                {
                    Otp.Erlang.Object reply = mbox.rpcCall(
                        remote, "global", "register_name",
                        new Otp.Erlang.List(new Otp.Erlang.Atom("me"), mbox.self()));

                    System.Console.Out.WriteLine("<= [REPLY2]:" + (reply == null ? "null" : reply.ToString()));
                }

                {
                    Otp.Erlang.Object reply = mbox.rpcCall(remote, "global", "register_name", new Otp.Erlang.List(new Otp.Erlang.Atom("me"), mbox.self()), 5000);
                    System.Console.Out.WriteLine("<= [REPLY3]:" + (reply == null ? "null" : reply.ToString()));
                }

                {
                    Otp.Erlang.Object reply = mbox.rpcCall(
                        remote, "io", "format",
                        new Otp.Erlang.List(
                            "Test: ~w -> ~w\n",
                            new Otp.Erlang.List(mbox.self(), new Otp.Erlang.Atom("ok"))
                            ));

                    System.Console.Out.WriteLine("<= [REPLY4]:" + (reply == null ? "null" : reply.ToString()));
                }

                while (true)
                {
                    Otp.Erlang.Object msg = mbox.receive();
                    if (msg is Otp.Erlang.Tuple)
                    {
                        Otp.Erlang.Tuple m = msg as Otp.Erlang.Tuple;
                        if (m.arity() == 2 && m.elementAt(0) is Otp.Erlang.Pid)
                        {
                            mbox.send(m.elementAt(0) as Otp.Erlang.Pid, m.elementAt(1));
                        }
                    }
                    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();
        }