Wednesday, July 9, 2014

What is Pipes? with a simple example in the .Net Framework

A pipe is a section of shared memory that processes use for communication. There are two types of pipes:

1. Anonymous pipes (Always for local communication, not for network communication)

2. Named pipes (For communication between server and clients. Any process can act as either a named pipe server or client, or both)

Namespace : System.IO.Pipes

To implement NamedPipes in the .Net Framework, Use “NamedPipeServerStreem” and “NamedPipeClientStream” classes.

Server Code Example:

Dim pipeServer As New NamedPipeServerStream("mypipe", PipeDirection.Out)
pipeServer.WaitForConnection()
Try 
   Dim sw As New StreamWriter(pipeServer)
   sw.AutoFlush = True 
   sw.WriteLine(Console.ReadLine())
Catch ex As IOException 
   Console.WriteLine("ERROR: {0}", ex.Message)
End Try 
 


Client Code Example:


Dim pipeClient As New NamedPipeClientStream("localhost", _
                    "mypipe", PipeDirection.In, PipeOptions.None)
pipeClient.Connect()
Dim sr As New StreamReader(pipeClient)
Dim temp As String

temp = sr.ReadLine()
While Not temp Is Nothing
   Console.WriteLine("From server: {0}", temp)
   temp = sr.ReadLine()
End While
Console.Write("Press Enter to continue...")
Console.ReadLine()
 


No comments:

Post a Comment

React-select is very slow on larger list - Found solution - using react-window

 I had more than 4000 items in searchable dropdownlist. I have used react-select but it was very slow. finally I found complete solution to ...