private void UpdateControllerClient() { ViewerScene viewerScene = null; try { viewerScene = controllerClientSocket.ReceiveViewerScene(); } catch (TcpSocketException e) { print($"TcpSocketException while receiving: {e}"); controllerClientSocket = null; return; } if (viewerScene != null) { foreach (var kinectSenderElement in viewerScene.kinectSenderElements) { IPAddress ipAddress; if (!IPAddress.TryParse(kinectSenderElement.address, out ipAddress)) { TextToaster.Toast($"Failed to parse {ipAddress} as an IP address."); } var endPoint = new IPEndPoint(ipAddress, kinectSenderElement.port); if (kinectReceivers.FirstOrDefault(x => x.SenderEndPoint == endPoint) != null) { continue; } TryConnectToKinectSender(endPoint); } foreach (var kinectReceiver in kinectReceivers) { var kinectSenderElement = viewerScene.kinectSenderElements.FirstOrDefault(x => x.address == kinectReceiver.SenderEndPoint.Address.ToString() && x.port == kinectReceiver.SenderEndPoint.Port); if (kinectSenderElement != null) { var kinectOrigin = kinectReceiver.KinectOrigin; if (kinectOrigin != null) { kinectOrigin.transform.localPosition = kinectSenderElement.position; kinectOrigin.transform.localRotation = kinectSenderElement.rotation; } } } this.viewerScene = viewerScene; } var receiverStates = new List <ReceiverState>(); foreach (var receiver in kinectReceivers) { var receiverState = new ReceiverState(receiver.SenderEndPoint.Address.ToString(), receiver.SenderEndPoint.Port, receiver.ReceiverSessionId); receiverStates.Add(receiverState); } try { controllerClientSocket.SendViewerState(receiverStates); } catch (TcpSocketException e) { print($"TcpSocketException while connecting: {e}"); controllerClientSocket = null; } }
private void UpdateControllerClient() { ControllerScene controllerScene = null; try { controllerScene = controllerClientSocket.ReceiveControllerScene(); } catch (TcpSocketException e) { print($"TcpSocketException while receiving from controller: {e}"); controllerClientSocket = null; return; } if (controllerScene != null) { foreach (var controllerNode in controllerScene.nodes) { if (!IPAddress.TryParse(controllerNode.senderAddress, out IPAddress ipAddress)) { TextToaster.Toast($"Failed to parse an IP address ({ipAddress}) from controller."); continue; } var senderEndPoint = new IPEndPoint(ipAddress, controllerNode.senderPort); if (receivers.Values.FirstOrDefault(x => x.SenderEndPoint.Equals(senderEndPoint)) != null) { continue; } StartCoroutine(TryConnectToKinectSender(senderEndPoint)); } foreach (var receiverPair in receivers) { var controllerNode = controllerScene.FindNode(receiverPair.Value.SenderEndPoint); if (controllerNode != null) { var kinectNode = sharedSpaceScene.GetKinectNode(receiverPair.Key); if (kinectNode != null) { kinectNode.transform.localPosition = controllerNode.position; kinectNode.transform.localRotation = controllerNode.rotation; } } } this.controllerScene = controllerScene; } var receiverStates = new List <ReceiverState>(); foreach (var receiver in receivers.Values) { var receiverState = new ReceiverState(receiver.ReceiverId, receiver.SenderId, receiver.SenderEndPoint); receiverStates.Add(receiverState); } try { controllerClientSocket.SendViewerState(receiverStates); } catch (TcpSocketException e) { print($"TcpSocketException while connecting: {e}"); controllerClientSocket = null; } }