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