Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 26, 2015 14:21
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/ba371d1f78829381e65d to your computer and use it in GitHub Desktop.
Save Fhernd/ba371d1f78829381e65d to your computer and use it in GitHub Desktop.
Uso de la clase NamedPIpeServerStream en C#.
// OrtizOL - xCSw - http://ortizol.blogspot.com
using System;
using System.IO;
using System.IO.Pipes;
namespace Receta.CSharp.R0526
{
public class UsoNamedPipeServerStream
{
public static void Main()
{
Console.WriteLine(Environment.NewLine);
using (NamedPipeServerStream servidorPipe = new NamedPipeServerStream("servidor", PipeDirection.Out))
{
Console.WriteLine ("Se ha creado un objeto `NamedPipeServerStream`.");
// Inicia la escucha de conexiones:
Console.WriteLine ("A espera de conexiones de clientes...");
servidorPipe.WaitForConnection();
Console.WriteLine ("Se ha conectado un cliente.");
try
{
// Lectura de datos y envío de estos al cliente:
using (StreamWriter sw = new StreamWriter(servidorPipe))
{
sw.AutoFlush = true;
Console.WriteLine ("Escriba dato a ser enviado al cliente: ");
sw.WriteLine(Console.ReadLine());
}
}
// En caso de se haya perdido la conexión con el cliente:
catch(IOException e)
{
Console.WriteLine ("Error: {0}", e.Message);
}
}
Console.WriteLine(Environment.NewLine);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment