Inheritance: OtpLocalNode
示例#1
0
文件: Test.cs 项目: bmizerany/jungerl
        public static 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;
            }

            String host = System.Net.Dns.GetHostName();
            String remote = args[0]+"@"+host;

            OtpNode node = new OtpNode("q@"+host);
            System.Console.Out.WriteLine("This node is called {0} and is using cookie='{1}'.",
                node.node(), node.cookie());
            bool ok=false;
            ok = node.ping(remote, 1000);
            if (ok)
                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();

                Erlang.Object[] rpc = new Erlang.Object[2];
                Erlang.Object[] call = new Erlang.Object[5];

                call[0] = new Erlang.Atom("call");
                call[1] = new Erlang.Atom("lists");
                call[2] = new Erlang.Atom("reverse");
                call[3] = new Erlang.List(new Erlang.List("Hello Erlang world!"));
                call[4] = mbox.self();

                rpc[0] = mbox.self();
                rpc[1] = new Erlang.Tuple(call);

                Erlang.Tuple rpcTuple = new Erlang.Tuple(rpc);
                System.Console.Out.WriteLine("=> "+rpcTuple.ToString());

                mbox.send("rex", remote, rpcTuple);
                Erlang.Object reply = mbox.receive(1000);

                System.Console.Out.WriteLine("<= "+reply.ToString());
            }
            catch (System.Exception)
            {
            }
            finally
            {
                node.closeMbox(mbox);
            }

            node.close();
        }
示例#2
0
		// package constructor: called by OtpNode:createMbox(name)
		// to create a named mbox
		internal OtpMbox(OtpNode home, Erlang.Pid self, System.String name)
		{
			this._self = self;
			this.home = home;
			this.name = name;
			this.queue = new GenericQueue();
			this.links = new Links(10);
            this.monitors = new System.Collections.Hashtable(49, (float)0.95);
		}
示例#3
0
文件: OtpMbox.cs 项目: trompa/jungerl
 // package constructor: called by OtpNode:createMbox(name)
 // to create a named mbox
 internal OtpMbox(OtpNode home, Erlang.Pid self, System.String name)
 {
     this._self    = self;
     this.home     = home;
     this.name     = name;
     this.queue    = new GenericQueue();
     this.links    = new Links(10);
     this.monitors = new System.Collections.Hashtable(49, (float)0.95);
 }
示例#4
0
        /*
         * Intiate and open a connection to a remote node.
         *
         * @exception C#.io.IOException if it was not possible to connect to the peer.
         *
         * @exception OtpAuthException if handshake resulted in an authentication error.
         */
        // package scope
        internal OtpCookedConnection(OtpNode self, OtpPeer other) : base(self, other)
        {
            this.self     = self;
            this.links    = new Links(25);
            this.monitors = new System.Collections.Hashtable(49, (float)0.95);

            thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
            thread.IsBackground = true;
            thread.Name         = "cooked connection2 " + self.node() + "->" + other.node();
            thread.Start();
        }
示例#5
0
		/*
		* Accept an incoming connection from a remote node. Used by {@link
		* OtpSelf#accept() OtpSelf.accept()} to create a connection
		* based on data received when handshaking with the peer node, when
		* the remote node is the connection intitiator.
		*
		* @exception C#.io.IOException if it was not possible to connect to the peer.
		*
		* @exception OtpAuthException if handshake resulted in an authentication error
		*/
		// package scope
		internal OtpCookedConnection(OtpNode self, System.Net.Sockets.TcpClient s):base(self, s)
		{
			this.self = self;
			this.links = new Links(25);
            this.monitors = new System.Collections.Hashtable(49, (float)0.95);

			thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
			thread.IsBackground = true;
			thread.Name = "cooked connection "+self.node()+" | "+s.ToString();
			thread.Start();
		}
示例#6
0
        /*
         * Accept an incoming connection from a remote node. Used by {@link
         * OtpSelf#accept() OtpSelf.accept()} to create a connection
         * based on data received when handshaking with the peer node, when
         * the remote node is the connection intitiator.
         *
         * @exception C#.io.IOException if it was not possible to connect to the peer.
         *
         * @exception OtpAuthException if handshake resulted in an authentication error
         */
        // package scope
        internal OtpCookedConnection(OtpNode self, System.Net.Sockets.TcpClient s) : base(self, s)
        {
            this.self     = self;
            this.links    = new Links(25);
            this.monitors = new System.Collections.Hashtable(49, (float)0.95);

            thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
            thread.IsBackground = true;
            thread.Name         = "cooked connection " + self.node() + " | " + s.ToString();
            thread.Start();
        }
示例#7
0
文件: OtpNode.cs 项目: trompa/jungerl
            internal Acceptor(OtpNode a_node, int port)
            {
                InitBlock(a_node);

                a_sock = new System.Net.Sockets.TcpListener(System.Net.Dns.GetHostEntry("localhost").AddressList[0], port);
                a_sock.Start();
                this.a_port  = ((System.Net.IPEndPoint)a_sock.LocalEndpoint).Port;
                a_node._port = this.a_port;

                publishPort();
                thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
                thread.IsBackground = true;
                thread.Name         = "acceptor " + a_node.node();
                thread.Start();
            }
示例#8
0
        private void ProcessInternal()
        {
            OtpNode node = new OtpNode(false, nodename, cookie, true);
            WriteLine("This node is called {0} and is using cookie='{1}'.",
                node.node(), node.cookie());

            OtpMbox mbox = node.createMbox();
            OtpCookedConnection.ConnectTimeout = CONNECT_TIMEOUT;
            OtpCookedConnection conn = null;

            try
            {
                while (!Stopping)
                {
                    bool needReconnect = (conn == null || conn.isConnected() == false);
                    if (needReconnect)
                        conn = node.connection(remote);

                    if (conn == null)
                    {
                        fireChanged(false);
                        Thread.Sleep(RECONNECT_DELAY);
                        continue;
                    }

                    if (needReconnect)
                    {
                        conn.OnReadWrite += OnReadWrite;

                        // 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();
                        WriteLine("   successfully connected to node " + remote + "\n");
                        fireChanged(true);
                    }
                    if (_commands.Count == 0)
                    {
                        Thread.Sleep(100);
                        continue;
                    }

                    OTPWorkerCommand cmd = new OTPWorkerCommand { type = OTPWorkerCommandType.NO_COMMAND, param = null };
                    lock (_commands_lock)
                    {
                        if (_commands.Count < 0)
                            continue;
                        cmd = _commands.Dequeue();
                    }
                    switch (cmd.type)
                    {
                        case OTPWorkerCommandType.GETLIST:
                            GetList(mbox, (Action<IEnumerable<Tuple<String, object>>>)cmd.param);
                            break;
                        case OTPWorkerCommandType.CLICKED:
                            SendDo(mbox, (Erlang.Object)cmd.param);
                            break;
                        default:
                            WriteLine("Unknown command: {0} {1}", cmd.type, cmd.param);
                            break;
                    }
                }

            }
            finally
            {
                node.closeMbox(mbox);
            }
            node.close();
        }
示例#9
0
		/*
		* Intiate and open a connection to a remote node.
		*
		* @exception C#.io.IOException if it was not possible to connect to the peer.
		*
		* @exception OtpAuthException if handshake resulted in an authentication error.
		*/
		// package scope
        internal OtpCookedConnection(OtpNode self, OtpPeer other)
            : this(self, other, self.cookie())
        {
        }
示例#10
0
文件: Test.cs 项目: trompa/jungerl
        static public void Main(String[] args)
        {
            OtpTrace.TraceEvent("Otp test...");

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

            String host   = System.Net.Dns.GetHostName();
            String remote = args[0] + "@" + host;

            OtpNode node = new OtpNode("q@" + host);

            OtpTrace.TraceEvent("This node is called {0} and is using cookie='{1}'.",
                                node.node(), node.cookie());
            bool ok = false;

            ok = node.ping(remote, 1000);
            if (ok)
            {
                OtpTrace.TraceEvent("   successfully pinged node " + remote + "\n");
            }
            else
            {
                OtpTrace.TraceEvent("   could not ping node " + remote + "\n");
            }

            OtpMbox mbox = null;

            try
            {
                mbox = node.createMbox();

                Erlang.Object[] rpc  = new Erlang.Object[2];
                Erlang.Object[] call = new Erlang.Object[5];

                call[0] = new Erlang.Atom("call");
                call[1] = new Erlang.Atom("lists");
                call[2] = new Erlang.Atom("reverse");
                call[3] = new Erlang.List(new Erlang.List("Hello Erlang world!"));
                call[4] = mbox.self();

                rpc[0] = mbox.self();
                rpc[1] = new Erlang.Tuple(call);

                Erlang.Tuple rpcTuple = new Erlang.Tuple(rpc);
                OtpTrace.TraceEvent("=> " + rpcTuple.ToString());

                mbox.send("rex", remote, rpcTuple);
                Erlang.Object reply = mbox.receive(1000);

                OtpTrace.TraceEvent("<= " + reply.ToString());
            }
            catch (System.Exception)
            {
            }
            finally
            {
                node.closeMbox(mbox);
            }

            node.close();
        }
示例#11
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();
        }
示例#12
0
文件: Test.cs 项目: saleyn/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();
        }
示例#13
0
文件: OtpNode.cs 项目: trompa/jungerl
 private void  InitBlock(OtpNode a_node)
 {
     this.a_node = a_node;
 }
示例#14
0
文件: Test.cs 项目: trompa/jungerl
        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();
        }
示例#15
0
文件: OtpNode.cs 项目: trompa/jungerl
 private void  InitBlock(OtpNode enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
示例#16
0
 // package constructor: called by OtpNode:createMbox(name)
 // to create a named mbox
 internal OtpMbox(OtpNode home, Erlang.Pid self, System.String name)
 {
     this._self = self;
     this.home = home;
     this.name = name;
     this.queue = new GenericQueue();
     this.links = new Links(10);
 }
示例#17
0
文件: OtpMbox.cs 项目: trompa/jungerl
 // package constructor: called by OtpNode:createMbox()
 // to create an anonymous
 internal OtpMbox(OtpNode home, Erlang.Pid self) : this(home, self, null)
 {
 }
示例#18
0
文件: Test.cs 项目: e42s/jungerl
        public static 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();
        }
示例#19
0
 /*
  * Intiate and open a connection to a remote node.
  *
  * @exception C#.io.IOException if it was not possible to connect to the peer.
  *
  * @exception OtpAuthException if handshake resulted in an authentication error.
  */
 // package scope
 internal OtpCookedConnection(OtpNode self, OtpPeer other)
     : this(self, other, self.cookie())
 {
 }
示例#20
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();
        }
示例#21
0
文件: OtpNode.cs 项目: saleyn/otp.net
			private void  InitBlock(OtpNode enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}
示例#22
0
 // package constructor: called by OtpNode:createMbox()
 // to create an anonymous
 internal OtpMbox(OtpNode home, Erlang.Pid self)
     : this(home, self, null)
 {
 }
示例#23
0
文件: OtpNode.cs 项目: saleyn/otp.net
			private System.Collections.Hashtable byName = null; // mbox names here
			
			public Mailboxes(OtpNode enclosingInstance)
			{
				InitBlock(enclosingInstance);
				byPid = new System.Collections.Hashtable(17, (float) 0.95);
				byName = new System.Collections.Hashtable(17, (float) 0.95);
			}
示例#24
0
文件: OtpNode.cs 项目: trompa/jungerl
            private System.Collections.Hashtable byName = null;             // mbox names here

            public Mailboxes(OtpNode enclosingInstance)
            {
                InitBlock(enclosingInstance);
                byPid  = new System.Collections.Hashtable(17, (float)0.95);
                byName = new System.Collections.Hashtable(17, (float)0.95);
            }
示例#25
0
文件: OtpNode.cs 项目: saleyn/otp.net
			private void  InitBlock(OtpNode a_node)
			{
				this.a_node = a_node;
			}
示例#26
0
文件: OtpNode.cs 项目: saleyn/otp.net
			internal Acceptor(OtpNode a_node, int port)
			{
				InitBlock(a_node);

				a_sock = new System.Net.Sockets.TcpListener(System.Net.Dns.GetHostEntry("localhost").AddressList[0], port);
				a_sock.Start();
				this.a_port = ((System.Net.IPEndPoint)a_sock.LocalEndpoint).Port;
				a_node._port = this.a_port;

				publishPort();
				thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
				thread.IsBackground = true;
				thread.Name = "acceptor "+a_node.node();
				thread.Start();
			}
示例#27
0
        /*
		* Intiate and open a connection to a remote node.
		*
		* @exception C#.io.IOException if it was not possible to connect to the peer.
		*
		* @exception OtpAuthException if handshake resulted in an authentication error.
		*/
		// package scope
		internal OtpCookedConnection(OtpNode self, OtpPeer other, string cookie)
            : base(self, other, cookie)
		{
			this.self = self;
			this.links = new Links(25);
            this.monitors = new System.Collections.Hashtable(49, (float)0.95);

			thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
			thread.IsBackground = true;
			thread.Name = "cooked connection2 "+self.node()+"->"+other.node();
			thread.Start();
		}
示例#28
0
文件: Test1.cs 项目: e42s/jungerl
        public static void Main(String[] args)
        {
            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();
        }
示例#29
0
        /*
        * Intiate and open a connection to a remote node.
        *
        * @exception C#.io.IOException if it was not possible to connect to the peer.
        *
        * @exception OtpAuthException if handshake resulted in an authentication error.
        */
        // package scope
        internal OtpCookedConnection(OtpNode self, OtpPeer other)
            : base(self, other)
        {
            this.self = self;
            this.links = new Links(25);

            thread = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
            thread.IsBackground = true;
            thread.Name = "cooked connection2 "+self.node()+"->"+other.node();
            thread.Start();
        }