Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 26, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/b54d6e019ad751b21d80 to your computer and use it in GitHub Desktop.
Save Fhernd/b54d6e019ad751b21d80 to your computer and use it in GitHub Desktop.
Demostración del uso de la clase NamedPipeClientStream en C#.
// OrtizOL - xCSw - http://ortizol.blogspot.com
using System;
using System.IO;
using System.IO.Pipes;
namespace Receta.CSharp.R0526
{
public class UsoNamedPipeClientStream
{
public static void Main()
{
Console.WriteLine(Environment.NewLine);
using (NamedPipeClientStream clientePipe = new NamedPipeClientStream(".", "servidor", PipeDirection.In))
{
Console.WriteLine ("Se ha creado un objeto `NamedPipeClientStream`.");
// Conexión a named pipe hasta que haya uno disponible:
Console.WriteLine ("Intentando conectar a un named pipe...");
clientePipe.Connect();
Console.WriteLine ("Se ha conectado a un servidor named pipe.");
Console.WriteLine ("Actualmente existen {0} named pipe en modo servidor abiertos.\n", clientePipe.NumberOfServerInstances.ToString());
// Lectura de datos y envío de estos al cliente:
using (StreamReader sr = new StreamReader(clientePipe))
{
// Lee el mensaje enviado desde el servidor:
string mensajeServidorPipe;
while ((mensajeServidorPipe = sr.ReadLine()) != null)
{
Console.WriteLine ("Mensaje recibido desde el servidor pipe: {0}", mensajeServidorPipe);
}
}
}
Console.WriteLine(Environment.NewLine);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment