public void SendData(string p_string) { if (VerifyIfIsConnectedToSocket() == false) { Debug.Log("Not connected"); return; } _tcpConnection.SendData(p_string); }
///// <summary> ///// INotifyPropertyChangedPropertyChanged event to allow window controls to bind to changeable data ///// </summary> //public event PropertyChangedEventHandler PropertyChanged; #endregion // Methods #region EventHandler /// <summary> /// Connect to central Kinectv2 server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ConnectButton_Click(object sender, RoutedEventArgs e) { // Retrieve the final decision of the IP address of the server serverIP = serverIP_TextBox.Text; // Write back as the default IP address System.IO.File.WriteAllText(filePathToServerIP, serverIP); if (isConnectingToServer == false) { /* Try to make the connection... */ try { status_TextBlock.Text = "Connecting... " + serverIP; /* Connect to server */ tcpConnector.SetupSockets(); tcpConnector.ConnectToServer(serverIP); status_TextBlock.Text = "Connected!"; /* Waiting for server welcome messages */ string serverFeedback = ""; while (serverFeedback == "") { serverFeedback = tcpConnector.ReceiveData_wait(); } Thread.Sleep(100); /* Tell the server this client type */ tcpConnector.SendData(tcpConnector.clientType.ToString()); /* Receive client ID from server */ serverFeedback = ""; while (serverFeedback == "") { serverFeedback = tcpConnector.ReceiveData_wait(); } /* Extract the client ID from the message of server */ string[] temp = serverFeedback.Split(' '); this.Title += "ID :" + temp[3]; //kinectID = Int32.Parse(temp[3]); kinectparameters_local.kinectID = Int32.Parse(temp[3]); Thread.Sleep(200); status_TextBlock.Text = "Sending Data..."; /* Start value updating thread */ updateResults = new UpdateResultsToServer(this); updateResultsThread = new Thread(new ThreadStart(this.updateResults.ThreadProc)); updateResultsThread.IsBackground = true; updateResultThreadAlive = true; updateResultsThread.Start(); /* Start kinect value printing thread */ printResults = new PrintTrackingResults(this); printResultsThread = new Thread(new ThreadStart(this.printResults.ThreadProc)); printResultsThread.IsBackground = true; printResultThreadAlive = true; printResultsThread.Start(); // State changed this.isConnectingToServer = true; /* Control the appearance of UI */ serverIP_TextBox.IsEnabled = false; connect_Button.Content = "Disconnect"; connect_Button.Background = System.Windows.Media.Brushes.LightPink; } catch (Exception ex) { status_TextBlock.Text = "Connection failed! : " + ex.ToString(); } } /* Disconnect from server... */ else { /* Close results updating thread */ this.updateResultThreadAlive = false; if (updateResultsThread != null) { while (updateResultsThread.IsAlive == true) { this.status_TextBlock.Text = "Closing update value thread..."; } } /* Close results printing thread */ this.printResultThreadAlive = false; if (printResultsThread != null) { while (printResultsThread.IsAlive == true) { this.status_TextBlock.Text = "Closing print value thread..."; } } try { string messageFromServer = tcpConnector.CloseConnection(); status_TextBlock.Text = messageFromServer; Thread.Sleep(1500); // State changed this.isConnectingToServer = false; /* Control the appearance of UI */ serverIP_TextBox.IsEnabled = true; connect_Button.Content = "Connect"; connect_Button.Background = System.Windows.Media.Brushes.LightGreen; status_TextBlock.Text = "Disconnected"; } catch (Exception ex) { status_TextBlock.Text = "Disconnection failed! : " + ex.ToString(); } } }