Created
July 26, 2015 14:28
-
-
Save Fhernd/b54d6e019ad751b21d80 to your computer and use it in GitHub Desktop.
Demostración del uso de la clase NamedPipeClientStream en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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