static void HUBReceiver() { char tempMessage; string[] poseInfo; // Receive kursor information HUBNotifierReceiver = new NamedPipesServer(); HUBNotifierReceiver.CreateNewServerPipe(HUBNotifierChannel, NamedPipesServer.PipeDirection.DirectionInOut, NamedPipesServer.SendMode.ByteMode); HUBNotifierReceiver.WaitForConnection(); tempMessage = (char)HUBNotifierReceiver.ReadByte(); HUBNotifierReceiver.WaitForPipeDrain(); HUBNotifierReceiver.Disconnect(); HUBNotifierReceiver.ClosePipe(); if (tempMessage == 'y') { ImageLoader(); } }
static void HUBNotifierReceiver() { Stopwatch HUBNotifierWatcher = new Stopwatch(); HUBNotifierWatcher.Start(); HUBNotifier = new NamedPipesServer(); HUBNotifier.CreateNewServerPipe(HUBNotifierChannel, NamedPipesServer.PipeDirection.DirectionInOut, NamedPipesServer.SendMode.ByteMode); HUBNotifier.WaitForConnection(); if ((char)HUBNotifier.ReadByte() == 'y') { ImageLoader(); } HUBNotifier.WaitForPipeDrain(); HUBNotifier.Disconnect(); HUBNotifier.ClosePipe(); HUBNotifierWatcher.Stop(); HUBReceiverPerformance = HUBNotifierWatcher.ElapsedMilliseconds; }
void ModelerThread() { ThreadHelperClass.SetText(this, lblStatusValue, "Requesting the HUB resolution..."); bool isExitRequested = false; char receivedCode; NamedPipesServer imageNotifier = new NamedPipesServer(); MMF ImageData; Bitmap imageReceived; #region Screen Resolution Request int width; int height; // Connect for first time check for resolution used by main program NamedPipesServer server = new NamedPipesServer(); server.CreateNewServerPipe("res-pipe", NamedPipesServer.PipeDirection.DirectionInOut, NamedPipesServer.SendMode.MessageMode); server.WaitForConnection(); string resolution = server.ReadMessage(); // Separate screen width and height string[] res = resolution.Split('x'); width = Convert.ToInt32(res[0]); height = Convert.ToInt32(res[1]); string receivedResolution = "Connected client resolution: " + width + " x " + height; ThreadHelperClass.SetText(this, lblStatusValue, "HUB's resolution received"); ThreadHelperClass.SetText(this, lblScreenResolutionValue, receivedResolution); #endregion Screen Resolution Request bool isFirstTime = true; do { ThreadHelperClass.SetText(this, lblStatusValue, "Waiting new notification..."); try { // Memory-mapped file access server.CreateNewServerPipe("ImageNotifier", NamedPipesServer.PipeDirection.DirectionInOut, NamedPipesServer.SendMode.ByteMode); server.WaitForConnection(); if (server.ReadByte() == (char)'y') { ThreadHelperClass.SetText(this, lblStatusValue, "Receiving image..."); byte[] file = null; Console.WriteLine('y'); // Load image from Memory-mapped file and display as texture for model. MMF mappedFile = new MMF(); mappedFile.OpenExisting("MapTest"); file = Convert.FromBase64String(mappedFile.ReadContent(MMF.DataType.DataString)); using (var ms = new MemoryStream(file)) { imageReceived = new Bitmap(ms); } ThreadHelperClass.SetImage(this, imgTesterPreviewImage, imageReceived); } } catch (Exception err) { throw; } server.Disconnect(); server.ClosePipe(); //try //{ // imageNotifier.CreateNewServerPipe("test-pipe", NamedPipesServer.PipeDirection.DirectionInOut, NamedPipesServer.SendMode.ByteMode); // imageNotifier.WaitForConnection(); // receivedCode = (char)imageNotifier.ReadByte(); // imageNotifier.WaitForPipeDrain(); // if (receivedCode == 'x') // isExitRequested = true; // else // isExitRequested = false; // if (receivedCode == 'y') // { // ThreadHelperClass.SetText(this, lblStatusValue, "New notification. Receiving..."); // byte[] file = null; // // Load image from Memory-mapped file // MMF mappedFile = new MMF(); // mappedFile.OpenExisting("MapTest"); // file = Convert.FromBase64String(mappedFile.ReadContent(MMF.DataType.DataString)); // using (var ms = new MemoryStream(file)) // { // imageReceived = new Bitmap(ms); // } // ThreadHelperClass.SetImage(this, previewImage, imageReceived); // } //} //catch (Exception err) //{ // throw; //} //server.Disconnect(); //server.ClosePipe(); } while (!isExitRequested); }