def Ping(self, remoteNodeName, pingCallback): """Ping a remote node. REMOTE-NODE-NAME = string | <instance of ErlAtom> The node to ping PING-CALLBACK = <function(RESULT): void> A callback to call for deliverance of the ping result. RESULT = "pong" | "pang". Returns: void Throws: <<to-be-documented>> Try to ping a remote node. A connection to that node is established unless already connected. Whether or not the remote node is up or down is indicated as by the argument to the callback function: "pong": the remote node is alive and there is a connection to it "pang": the remote node is down. """ if not "@" in remoteNodeName: raise ErlNodeBadPeerNameError(remoteNodeName) if remoteNodeName in self._ongoingPings: pingCallbacks = self._ongoingPings[remoteNodeName] self._ongoingPings[remoteNodeName] = pingCallbacks + [pingCallback] else: self._ongoingPings[remoteNodeName] = [pingCallback] [nodeName, hostName] = remoteNodeName.split("@") e = erl_epmd.ErlEpmd(hostName) cb = erl_common.Callback(self._PingEpmdResponse, remoteNodeName) e.PortPlease2Req(nodeName, cb)
def __init__(self, nodeName, opts=erl_opts.ErlNodeOpts()): """Constructor. NODE-NAME = string The name for this node. OPTS = <instance of ErlNodeOpts> Creates an ErlNode. The name of the node is determined by NODE-NAME as described below. A node-name consists of two parts: an alive-name and a host-name, separated by an `@'. The host-name can be short (not including the domain) or long (including the domain). Short and long node-names must not be mixed among the nodes in a system, see the erlang documentation for further details. 1. If the NODE-NAME contains an `@', then NODE-NAME is used unchanged as name for the node. 2. If the NODE-NAME does not contain an `@', then the node's name is constructed as NODE-NAME + "@" + host-name, where host-name is either on short or long form, depending on what is specified in the OPTS. """ shortNodeNames = opts.GetShortNodeNames() self._nodeName = erl_common.AlignNodeName(nodeName, shortNodeNames) self._opts = opts self._creation = 0 self._connections = {} self._epmd = erl_epmd.ErlEpmd(hostName=opts.GetEpmdHost(), portNum=opts.GetEpmdPort()) self._ongoingPings = {} self._isServerPublished = 0 self._pids = {} # mapping pid --> ErlMBox() self._mboxes = {} # mapping ErlMBox --> pid self._registeredNames = {} # mapping name --> pid self._registeredPids = {} # mapping pid --> name self._nodeUpCb = [] # stores (id, callback) self._nodeDownCb = [] # stores (id, callback) self._cbId = 0 self._server = erl_node_conn.ErlNodeServerSocket( self._nodeName, self._opts) self._portNum = self._server.Start(self._NodeUp, self._NodeDown, self._PassThroughMsg) self._epmd.SetOwnPortNum(self._portNum) self._epmd.SetOwnNodeName(self._nodeName) self._epmdConnectedOkCb = erl_common.Callback(self._Sink) self._CreateRex()
hostName = "localhost" portNum = 4369 ownPortNum = 1234 ownNodeName = "py_interface_test" for (optchar, optarg) in opts: if optchar == "-?": print "Usage: %s host [port]" % argv[0] sys.exit(1) elif optchar == "-p": ownPortNum = string.atoi(optarg) elif optchar == "-n": ownNodeName = optarg if len(args) >= 2: hostName = args[0] portNum = string.atoi(args[1]) elif len(args) == 1: hostName = args[0] e = erl_epmd.ErlEpmd(hostName, portNum) e.SetOwnPortNum(ownPortNum) e.SetOwnNodeName(ownNodeName) e.Connect(TestAlive2RespConnected, TestAlive2RespConnectFailed) evhandler = erl_eventhandler.GetEventHandler() evhandler.Loop() main(sys.argv)