void OnEnable() { DebugUtilities.UserMessage("Hollo World . . ."); #if UNITY_ANDROID Thread.Sleep(1500); #endif DebugUtilities.UserMessage("Your IP is:\n" + NetworkUtilities.LocalIPAddress()); #if UNITY_ANDROID Thread.Sleep(3500); #endif DebugUtilities.UserMessage("Place your CPlane by tapping on scanned mesh."); }
////////////////////////////////////////////////////////////////////////// #if WINDOWS_UWP private async void StartReceiving() { // Reset. // Start receiving. this.client = new DatagramSocket(); this.client.MessageReceived += ReceiveData; try { await client.BindEndpointAsync(new HostName(NetworkUtilities.LocalIPAddress()), this.localPort.ToString()); } catch (Exception exception) { #if DEBUGWARNING DebugUtilities.UniversalWarning(this.sourceName, "Exception: " + exception.ToString() + ":" + SocketError.GetStatus(exception.HResult).ToString(), ref this.debugMessages); #endif } #if DEBUG DebugUtilities.UniversalDebug(this.sourceName, "Client receivng thread Started.", ref this.debugMessages); #endif }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { // Get inputs. Connection connect = null; if (!DA.GetData(0, ref connect)) { return; } ////////////////////////////////////////////////////// // Process data. if (connect.status) { // If connection open start acting. if (!UIReceiver.flagProcessed) { UIReceiver.flagProcessed = true; // Send local IPAddress for device to communicate back. byte[] bytes = EncodeUtilities.EncodeData("IPADDRESS", NetworkUtilities.LocalIPAddress(), out string currentMessage); connect.udpSender.Send(bytes); bool success = connect.udpSender.success; UniversalDebug("Sent local IP."); } // Prepare to receive UI data. try { if (!connect.udpReceiver.flagDataRead) { connect.udpReceiver.flagDataRead = true; UIReceiver.currentInput = connect.udpReceiver.dataMessages[connect.udpReceiver.dataMessages.Count - 1]; if (UIReceiver.lastInputs != currentInput) { currentInput = EncodeUtilities.StripSplitter(currentInput); UIReceiver.lastInputs = currentInput; UniversalDebug("New Message without Message Splitter removed: " + currentInput); string[] messageComponents = currentInput.Split(new string[] { EncodeUtilities.headerSplitter }, 2, StringSplitOptions.RemoveEmptyEntries); if (messageComponents.Length > 1) { string header = messageComponents[0], content = messageComponents[1]; UniversalDebug("Header: " + header + ", content: " + content); if (header == "UIDATA") { // If any new data received - process it. UIData data = JsonConvert.DeserializeObject <UIData>(content); UIReceiver.currentBools = new List <bool> (data.bools); UIReceiver.currentInts = new List <int> (data.ints); UIReceiver.currentFloats = new List <float> (data.floats); UniversalDebug("Data Received!"); } else { UniversalDebug("Header Not Recognized!", GH_RuntimeMessageLevel.Warning); } } else { UniversalDebug("Data not Received!", GH_RuntimeMessageLevel.Warning); } } else { UniversalDebug("Improper Message!", GH_RuntimeMessageLevel.Warning); } } else { UniversalDebug("No data received."); } } catch { UniversalDebug("Error Processing Data.", GH_RuntimeMessageLevel.Error); } } else { // If connection disabled - stop receiving. UIReceiver.flagProcessed = false; UIReceiver.lastInputs = string.Empty; UIReceiver.currentBools = new List <bool>(); UIReceiver.currentInts = new List <int>(); UIReceiver.currentFloats = new List <float>(); UniversalDebug("Set 'Send' on true in HoloFab 'HoloConnect'", GH_RuntimeMessageLevel.Warning); } ////////////////////////////////////////////////////// // Output. DA.SetDataList(0, UIReceiver.currentBools); DA.SetDataList(1, UIReceiver.currentInts); DA.SetDataList(2, UIReceiver.currentFloats); #if DEBUG DA.SetData(3, this.debugMessages[this.debugMessages.Count - 1]); #endif // Expire Solution. if (connect.status) { GH_Document document = this.OnPingDocument(); if (document != null) { document.ScheduleSolution(UIReceiver.expireDelay, ScheduleCallback); } } }