示例#1
0
    public byte[] update()
    {
        if (client.IsAttentionRequired) // when server response msg NEWLY arrived
        {
            if (sub == null)
            {
                if (client.TargetPort < 1)
                {
                    Debug.Log("no publisher found");
                    client.sendMyInfo();
                    return(null);
                }
                sub = new DRSocket(client.ClientName);
                Debug.Log("connectig to : " + client.TargetPort);
                sub.setMyInfo(false, client.MyIp, client.TargetNodeName);
                sub.connectToServer(client.TargetIP, client.TargetPort);
                sub.sendMyInfo();
                client.IsAttentionRequired = false;
            }

            if (sub.isConnected())
            {
                okToSubscribe = true;
            }
            return(null);
        }
        else if (okToSubscribe) // server reponse msg is already porcessed and connected to publisher
        {
            Debug.Log("here 1");
            if (sub.IsNewlyReceived)
            {
                Debug.Log("here 2");
                sub.IsNewlyReceived = false;
                byte[] bMsg = sub.getRecentData();
                return(bMsg);
            }
            else
            {
                return(null);
            }
        }
        else // when server response msg not arrived
        {
            if (sub == null)
            {
                return(null);
            }
            if (!sub.isConnected())
            {
                if (!sub.isConnected())
                {
                    okToSubscribe = false;
                }
                client.TargetPort          = -1;
                client.IsAttentionRequired = true;
                sub = null;
            }
            return(null);
        }
    }
示例#2
0
    public DRSubscriber(string name, string serverIP, int serverPort, string targetPubName)
    {
        this.serverIP   = serverIP;
        this.serverPort = serverPort;

        okToSubscribe = false;
        isConnected   = false;
        client        = new DRSocket(name);
        client.connectToServer(serverIP, serverPort);
        isConnected = client.IsSocketReady;
        client.setMyInfo(false, "127.0.0.1", targetPubName);
        client.sendMyInfo();
        Thread connThread = new Thread(new ThreadStart(connMethod));

        connThread.Start();
    }
示例#3
0
 public DRSubscriber(string name, string serverIP, int serverPort, string targetPubName)
 {
     okToSubscribe = false;
     isConnected   = false;
     client        = new DRSocket(name);
     client.connectToServer(serverIP, serverPort);
     isConnected = client.IsSocketReady;
     client.setMyInfo(false, "127.0.0.1", targetPubName);
     client.sendMyInfo();
     while (!client.IsAttentionRequired)
     {
         if (serverCheckCount > 60 * 5)
         {
             Debug.Log("is DRMonitor there?");
             QuitGame();
         }
         Debug.Log(client.IsAttentionRequired);
         serverCheckCount++;
         Thread.Sleep(100);
     }
 }
示例#4
0
    public byte[] update()
    {
        if (client.IsAttentionRequired)
        {
            if (sub == null)
            {
                if (client.TargetPort == -1)
                {
                    Debug.Log("no publisher found");
                    QuitGame();
                    return(null);
                }
                sub = new DRSocket(client.ClientName);
                Debug.Log("connectig to : " + client.TargetPort);
                sub.setMyInfo(false, client.MyIp, client.TargetNodeName);
                sub.connectToServer(client.MyIp, client.TargetPort);
                sub.sendMyInfo();
            }
            client.IsAttentionRequired = false;
            if (sub.isConnected())
            {
                okToSubscribe = true;
            }
        }

        if (!okToSubscribe)
        {
            return(null);
        }
        if (sub.IsNewlyReceived && okToSubscribe)
        {
            sub.IsNewlyReceived = false;
            byte[] bMsg = sub.getRecentData();
            return(bMsg);
        }
        else
        {
            return(null);
        }
    }