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); } }
private void constructorHelper(string name, string serverIP, int serverPort) { isConnected = false; okToPublish = false; updateRate = 0; client = new DRSocket(name); client.IsPublisher = true; client.connectToServer(serverIP, serverPort); isConnected = client.IsSocketReady; client.sendMyInfo(); while (!client.IsAttentionRequired) { if (serverCheckCount > 60 * 5) { Debug.Log("is DRMonitor there?"); throw new Exception(); } Debug.Log(client.IsAttentionRequired); serverCheckCount++; Thread.Sleep(20); } okToPublish = true; Debug.Log("port to pub: " + client.TopicPort); openTopicRegistrationDesk(); }
public void updateGUI(GameObject panel_runningApps, GameObject panel_connectedApp, AddNewAppPanel createNewAppPanel) { 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; // update GUI if (node.ClientName.Length >= 5) { if (node.ClientName.Substring(0, 5).Equals("guest")) { return; } } string text = getAppInfo(node); if (connectedAppDict.ContainsKey(node.ClientName)) { GameObject temp = connectedAppDict[node.ClientName]; temp.GetComponentInChildren <Text>().text = text; } else //creat and add { GameObject temp = createNewAppPanel(); temp.GetComponentInChildren <Text>().text = text; connectedAppDict.Add(node.ClientName, temp); } } }
/// <summary> /// Can be called when deep copy is necessary. /// </summary> /// <param name="drSocket">The object to deep copy</param> public DRSocket(DRSocket drSocket) : this() { targetIP = drSocket.TargetIP; dataStoragePtr = drSocket.DataStoragePtr; dataStorage = drSocket.DataStorage; tcp = drSocket.Tcp; clientName = drSocket.ClientName; isNewlyRecieved = drSocket.IsNewlyReceived; recievedData = drSocket.RecievedData; isSocketReady = drSocket.IsSocketReady; }
private void async_onNewRequest(IAsyncResult ar) { TcpListener listener = (TcpListener)ar.AsyncState; var drSocket = new DRSocket(listener.EndAcceptSocket(ar)); if (onRequest == null) { throw new NullReferenceException(); } onRequest(drSocket); async_startListening(); }
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; } } }
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(); }
private void constructorHelper(string name, string serverIP, int serverPort) { this.serverIP = serverIP; this.serverPort = serverPort; isConnected = false; okToPublish = false; updateRate = 0; client = new DRSocket(name); client.IsPublisher = true; client.connectToServer(serverIP, serverPort); isConnected = client.IsSocketReady; Thread connThread = new Thread(new ThreadStart(connMethod)); connThread.Start(); }
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); }
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); } }
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); } }
private void addNewNode(DRSocket drSocket) { int count = 0; while (drSocket.ClientName.Length >= 5 && drSocket.ClientName.Substring(0, 5).Equals("guest")) { if (count > 10 * 10) { throw new Exception(); } Thread.Sleep(100); count++; } if (nodeDict.ContainsKey(drSocket.ClientName)) { nodeDict[drSocket.ClientName] = drSocket; } else { nodeDict.Add(drSocket.ClientName, drSocket); } drSocket.getRemoteIP(); Debug.Log("new app attached"); }