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(); }
/// <summary> /// @see com.lowagie.text.pdf.PdfDictionary#toPdf(com.lowagie.text.pdf.PdfWriter, java.io.OutputStream) /// </summary> public override void ToPdf(PdfWriter writer, Stream os) { if (InputStream != null && Compressed) { Put(PdfName.Filter, PdfName.Flatedecode); } PdfEncryption crypto = null; if (writer != null) { crypto = writer.Encryption; } if (crypto != null) { PdfObject filter = Get(PdfName.Filter); if (filter != null) { if (PdfName.Crypt.Equals(filter)) { crypto = null; } else if (filter.IsArray()) { PdfArray a = (PdfArray)filter; if (!a.IsEmpty() && PdfName.Crypt.Equals(a[0])) { crypto = null; } } } } if (crypto != null && crypto.IsEmbeddedFilesOnly()) { PdfArray filter = new PdfArray(); PdfArray decodeparms = new PdfArray(); PdfDictionary crypt = new PdfDictionary(); crypt.Put(PdfName.Name, PdfName.Stdcf); filter.Add(PdfName.Crypt); decodeparms.Add(crypt); if (Compressed) { filter.Add(PdfName.Flatedecode); decodeparms.Add(new PdfNull()); } Put(PdfName.Filter, filter); Put(PdfName.Decodeparms, decodeparms); } PdfObject nn = Get(PdfName.LENGTH); if (crypto != null && nn != null && nn.IsNumber()) { int sz = ((PdfNumber)nn).IntValue; Put(PdfName.LENGTH, new PdfNumber(crypto.CalculateStreamSize(sz))); SuperToPdf(writer, os); Put(PdfName.LENGTH, nn); } else { SuperToPdf(writer, os); } os.Write(Startstream, 0, Startstream.Length); if (InputStream != null) { rawLength = 0; ZDeflaterOutputStream def = null; OutputStreamCounter osc = new OutputStreamCounter(os); OutputStreamEncryption ose = null; Stream fout = osc; if (crypto != null) { fout = ose = crypto.GetEncryptionStream(fout); } if (Compressed) { fout = def = new ZDeflaterOutputStream(fout, CompressionLevel); } byte[] buf = new byte[4192]; while (true) { int n = InputStream.Read(buf, 0, buf.Length); if (n <= 0) { break; } fout.Write(buf, 0, n); rawLength += n; } if (def != null) { def.Finish(); } if (ose != null) { ose.Finish(); } InputStreamLength = osc.Counter; } else { if (crypto == null) { if (StreamBytes != null) { StreamBytes.WriteTo(os); } else { os.Write(Bytes, 0, Bytes.Length); } } else { byte[] b; if (StreamBytes != null) { b = crypto.EncryptByteArray(StreamBytes.ToArray()); } else { b = crypto.EncryptByteArray(Bytes); } os.Write(b, 0, b.Length); } } os.Write(Endstream, 0, Endstream.Length); }