private void ServerThread() //pipe server thread { NamedPipeServerStream pipeServer = new NamedPipeServerStream("HarryThePipe", PipeDirection.InOut); //Create the named pipe, named SuperPipe, can send and recieve data UnityEngine.Debug.Log("Wait For Client"); pipeServer.WaitForConnection(); //Wait until client connects to server; wait for MATLAB to connect through attached c# code UnityEngine.Debug.Log("Client connected "); StreamBytes serverStream = new StreamBytes(pipeServer); while (pipeServer.IsConnected) { while (activeValues) { for (int simMonth = monthStart; simMonth <= monthFinish; simMonth++) { monthSun = simMonth; for (int simDay = dayStart; simDay <= dayFinish; simDay++) { daySun = simDay; for (int simHour = hourStart; simHour <= hourFinish; simHour++) { hourSun = simHour; Thread.Sleep(120); for (int i = 0; i < 6; i++) { serverStream.WriteBytes(Math.Round(cellSpace[i], 1)); pipeServer.Flush(); } Thread.Sleep(100); dataFromClient = serverStream.ReadBytes(); dataFromClient1 = serverStream.ReadBytes(); dataFromClient2 = serverStream.ReadBytes(); Save(simMonth, simDay, simHour, Math.Round(dataFromClient, 1)); Thread.Sleep(850); } if ((simMonth == 2 && simDay == 28) || ((simMonth == 4 || simMonth == 6 || simMonth == 9 || simMonth == 11) && simDay == 30)) { simDay = 32; } UnityEngine.Debug.Log("End of Day"); } //Collect only July and January //if (simMonth == 1) //{ // simMonth = 6; //} //else if (simMonth == 7) //{ // simMonth = 12; //} } activeValues = false; } } pipeServer.Close(); }
private void ServerThread() //pipe server thread { NamedPipeServerStream pipeServer = new NamedPipeServerStream("HarryThePipe", PipeDirection.InOut); //Create the named pipe, named SuperPipe, can send and recieve data UnityEngine.Debug.Log("Wait For Client"); pipeServer.WaitForConnection(); //Wait until client connects to server; wait for MATLAB to connect through attached c# code UnityEngine.Debug.Log("Client connected "); StreamBytes serverStream = new StreamBytes(pipeServer); while (pipeServer.IsConnected) { while (activeValues) { for (int i = 0; i < 6; i++) { if (i == 5) { serverStream.WriteBytes(0); } else { serverStream.WriteBytes(cellSpace[i]); } pipeServer.Flush(); } Thread.Sleep(100); dataFromClient = serverStream.ReadBytes(); dataFromClient1 = serverStream.ReadBytes(); dataFromClient2 = serverStream.ReadBytes(); Thread.Sleep(350); } } pipeServer.Close(); }