Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // Create a name pipe
            NamedPipeServerStream pipeStream = null;
            try
            {
                pipeStream = new NamedPipeServerStream(LogManager.ConnectionName, PipeDirection.InOut, 1, PipeTransmissionMode.Message);
                Console.WriteLine("Log Monitor started: " + pipeStream.GetHashCode());

                // Wait for a connection
                pipeStream.WaitForConnection();
                Console.WriteLine("Connection established");

                using (StreamReader sr = new StreamReader(pipeStream))
                {
                    pipeStream = null;

                    string temp;
                    // We read a line from the pipe and print it together with the current time
                    while ((temp = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(temp);
                    }
                }
            }
            finally
            {
                if (pipeStream != null)
                {
                    pipeStream.Dispose();
                }
            }

            Console.WriteLine("Connection lost");
            Console.WriteLine("Press <ENTER> to quit");
            Console.ReadLine();
        }
Exemplo n.º 2
0
 public static NamedPipeServerStream createNamePipeServer(string pipeName, Action<string> dataReceived, Action onPipeTerminated)
 {
     var namedPipeServerStream = new NamedPipeServerStream(pipeName);
     "[NamePipeServer][{0}] Pipe created {1}".format(pipeName, namedPipeServerStream.GetHashCode()).info();
     O2Thread.mtaThread(
         () =>
         {
             namedPipeServerStream.WaitForConnection();
             "[NamePipeServer][{0}] Pipe connection established".format(pipeName).info();
             using (var streamReader = new StreamReader(namedPipeServerStream))
             {
                 string line;
                 while ((line = streamReader.ReadLine()) != null)
                 {
                     //"received text:{0}".format(line).debug();
                     dataReceived(line);
                 }
                 "[NamePipeServer][{0}] Connection lost or pipe terminated".format(pipeName).info();
                 if (onPipeTerminated != null)
                     onPipeTerminated();
             }
         });
     return namedPipeServerStream;
 }
        public void ThreadStartServer(object o)
        {
            // Create a name pipe
            using (NamedPipeServerStream pipeStream = new NamedPipeServerStream("CommPipe"))
            {
                Console.WriteLine("[Server] Pipe created {0}", pipeStream.GetHashCode());

                // Wait for a connection
                pipeStream.WaitForConnection();
                MainWindow.obj.Name += "\n[Server] Pipe connection established";
                using (StreamReader sr = new StreamReader(pipeStream))
                {
                    string temp;
                    // We read a line from the pipe and print it together with the current time
                    var ViewModel = o as IImageListViewModel; 
                    while ((temp = sr.ReadLine()) != "End Connection")
                    {
                        if (temp != null)
                            MainWindow.obj.Name += "\n" + temp;
                    }
                    MainWindow.obj.Name += "\n[Server] Connection terminated";
                }
            }
        }