There are different types of way through which we implement the Inter Process Communication.
What is IPC?
IPC stands for Inter Process Communication. It means that two process communicate between them. We implement the IPC in .Net using the following ways:-
1. Shared Memory
2. Remoting
3. Mapped memory
4. Socket
5. Pipe
The pipe is the new way for implementing the IPC in .net 3.5. Before .net 3.5. we implement the Pipe by using the Microsoft.Win32 Namespace. But in .Net 3.5 the pipe is available under the System.IO.Pipe namespace. To implement the IPC using pipe we use two class from the System.IO.Pipe namespace.
1. NamedPipeServerStream
2.NamedPipeClienStream.
The programm which create the pipe is called the pipe server, and the programm which listen the programm is called the pipe client.
constructor For crating the Pipe server.
using System.IO.Pipe
class pipeServer
{
public pipeServer()
{
NamedPipeServerStream pipeServerStream=new NamedPipeServerStream("pipeServerMessaging",PipeDirection.In);
pipeServerStream.WaitForConnection();
}
}
Note:- In the above code NamedPipeServerStream is a class which creates the Pipe server, pipeServerStream is the object of the NamedPipeServerStream, the string written in double quote "pipeServerMessaging" is the name of the pipe, and PipeDirection is the enumeration which show the direction of the pipe.
After instantiating the pipeServerStream object, it wait for the connection.
Save it with .cs extension like other programs are saved in c#.
Now, create the pipe client
To create the pipe client we use the NamedPipeClientStream which are available in the System.IO.Pipe namespace
code for creating the pipe client
using System.IO.Pipe
class pipeClient
{
public pipeClient()
{
NamedPipeClientStream pipeClientStream=new NamedPipeClientStream("localhost","pipeServerMessaging", PipeDirection.Out);
pipeClient.Connect();
Console.WriteLine("Client Connected to the Server");
}
}
Note:- The following points keeps in mind when we create a pipe client
1. NamedPipeClientStream Constructor takes at least three argument.
A) Name of the computer on which your pipe server is running, if it is running on the local computer or on the same computer we pass the name of the computer "localhost" or "." . If the pipe server is running on the remote computer we pass the IP address of the remote computer or the name of the remote computer.
B) The second argument is the name of the pipe which is same as the pipe server.
C) The last argument is the pipe direction , which may be three value form the PipeDirection enumeration
Value of the PipeDirection
PipeDirection.In
PipeDirection.Out
PipeDirection.InOut
Caution:-
Save it with pipeClient.cs
Run the PipeServer programm first and the pipeClient.
This is the simple pipe demo for IPC
Subscribe to:
Post Comments (Atom)
3 comments:
good hai.... gr8 yaar. NIce question and answerbut i dont understand .net.
Anyways nice work done.
Thanks
hi,
i am using the above code.. the connection established. Then how to send the array of data to server machine through client application.
Post a Comment