示例#1
0
    private void update()
    {
        Dictionary <string, DRSocket> nodeDict = nodeManager.NodeDict;

        Debug.Log("here: " + nodeDict.Count);
        // deal with attention request
        foreach (KeyValuePair <string, DRSocket> nodePair in nodeDict)
        {
            DRSocket node = nodePair.Value;
            if (node.isConnected() && node.IsAttentionRequired)
            {
                // if node is publisher
                if (node.IsPublisher)
                {
                    node.TopicPort = ++port;
                    node.sendMyInfo();
                }
                // if node is subscriber, find publisher and notice the publisher ip & port.
                else
                {
                    string targetName = node.TargetNodeName;
                    Debug.Log("++++++" + targetName);
                    Debug.Log("++++++" + nodeDict.ContainsKey(targetName));
                    if (nodeDict.ContainsKey(targetName))
                    {
                        Debug.Log("++++++" + nodeDict[targetName].isConnected());
                    }
                    if (nodeDict.ContainsKey(targetName) && nodeDict[targetName].isConnected())
                    {
                        DRSocket temp = nodeDict[targetName];
                        node.TargetPort = temp.TopicPort;
                        node.TargetIP   = temp.MyIp;
                        Debug.Log(temp.TopicPort);
                        var targetNode = nodeDict[targetName];
                        node.sendMyInfo();
                        Debug.Log(node.ClientName + " is requesting " + node.TargetNodeName + " : " + node.TargetIP + " : " + node.TargetPort);
                    }
                    else
                    {
                        node.TargetIP   = "0.0.0.0";
                        node.TargetPort = -1;
                        node.sendMyInfo();
                    }
                }
                node.IsAttentionRequired = false;
            }
        }
    }
示例#2
0
    private string getAppInfo(DRSocket node)
    {
        string text = "";

        if (node.isConnected())
        {
            Debug.Log(node.ClientName + " is alive");
            text = node.ClientName + " alive";
            if (node.IsPublisher)
            {
                text += " at " + node.MyIp + ":" + node.TopicPort;
            }
        }
        else
        {
            text = node.ClientName + " lost";
        }
        return(text);
    }