/* * this method simulates net_kernel only for * the purpose of replying to pings. */ private bool netKernel(OtpMsg m) { OtpMbox mbox = null; try { Erlang.Tuple t = (Erlang.Tuple)(m.getMsg()); Erlang.Tuple req = (Erlang.Tuple)t.elementAt(1); // actual request Erlang.Pid pid = (Erlang.Pid)req.elementAt(0); // originating pid Erlang.Object[] pong = new Erlang.Object[2]; pong[0] = req.elementAt(1); // his #Ref pong[1] = new Erlang.Atom("yes"); mbox = createMbox(); mbox.send(pid, new Erlang.Tuple(pong)); return(true); } catch (System.Exception) { } finally { closeMbox(mbox); } return(false); }
/* * <p> Determine if another node is alive. This method has the side * effect of setting up a connection to the remote node (if * possible). Only a single outgoing message is sent; the timeout is * how long to wait for a response. </p> * * <p> Only a single attempt is made to connect to the remote node, * so for example it is not possible to specify an extremely long * timeout and expect to be notified when the node eventually comes * up. If you wish to wait for a remote node to be started, the * following construction may be useful: </p> * * <pre> * // ping every 2 seconds until positive response * while (!me.ping(him,2000)); * </pre> * * @param node the name of the node to ping. * * @param timeout the time, in milliseconds, to wait for response * before returning false. * * @return true if the node was alive and the correct ping response * was returned. false if the correct response was not returned on * time. **/ /*internal info about the message formats... * * the request: * -> REG_SEND {6,#Pid<[email protected]>,'',net_kernel} * {'$gen_call',{#Pid<[email protected]>,#Ref<[email protected]>},{is_auth,bingo@aule}} * * the reply: * <- SEND {2,'',#Pid<[email protected]>} * {#Ref<[email protected]>,yes} */ public virtual bool ping(System.String node, long timeout) { if (node.Equals(this._node)) { return(true); } OtpMbox mbox = null; try { mbox = createMbox(); mbox.send("net_kernel", node, getPingTuple(mbox)); Erlang.Object reply = mbox.receive(timeout); Erlang.Tuple t = (Erlang.Tuple)reply; Erlang.Atom a = (Erlang.Atom)(t.elementAt(1)); return("yes".Equals(a.atomValue())); } catch (System.Exception) { } finally { closeMbox(mbox); } return(false); }