private void SendStartMessage() { // Send Start message, wait for returned state = enabled bool enabled = false; while (enabled == false) { try { Log("Sending Start message."); // Send message TcpClient client = new TcpClient(mTestServer, Definitions.mPortNumber); Send(client, AutomationTestMessageID.StartMessageRequest, null); byte[] buffer = new byte[8]; // The timeout is important to prevent a socket from getting stuck client.Client.ReceiveTimeout = 10000; // ms timeout int read = client.Client.Receive(buffer, 8, SocketFlags.None); if (read > 0) { // Wait for response int dataLength = BitConverter.ToInt32(buffer, 4); buffer = new byte[dataLength]; client.Client.Receive(buffer, dataLength, SocketFlags.None); mStartClientResponse = JsonHelper.ToObject <StartClientResponse>(buffer); enabled = mStartClientResponse.Enabled; Log("Start response: enable=" + enabled + ", OS=" + mStartClientResponse.OSType); } client.Close(); } catch (Exception ex) { Log("Exception: " + ex); } if (enabled == false) { Thread.Sleep(30000); } } Console.WriteLine("VM enabled for OS " + mStartClientResponse.OSType); }
internal StartClientResponse HandleStartMessage() { Log("Start message received."); // Get latest state mData = VMInstanceData.SelectByIP(mData.IPAddress); // Reset local flags that represent the state of the VM mBusy = false; StartClientResponse response = new StartClientResponse() { Enabled = (mData.State == 1), OSType = mData.OperatingSystemID }; Log("Start response: Enabled=" + response.Enabled + "; OS=" + response.OSType); return(response); }