Created
July 26, 2015 14:21
-
-
Save Fhernd/ba371d1f78829381e65d to your computer and use it in GitHub Desktop.
Uso de la clase NamedPIpeServerStream 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 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