 |
|
|
|
 |
|
Inter-Process Communication in .NET Using Named Pipes, Part 2
5. Client Pipe Connections
To connect a client application to the server using Named Pipes we have to create an instance of the ClientPipeConnection class and use its methods for reading and writing data. The following code illustrates that:
IInterProcessConnection clientConnection = null;
try {
clientConnection = new ClientPipeConnection("MyPipe", ".");
clientConnection.Connect();
clientConnection.Write(textBox1.Text);
clientConnection.Close();
}
catch {
clientConnection.Dispose();
}
The name of the pipe "MyPipe" needs to be the same as the name used to create the server pipe. If the Named Pipes server is on the same machine ,then the second parameter of the ClientPipeConnection constructor is ".". Otherwise it needs to be the network name of the server machine.
It is important to always call the Dispose method when we have finished working with the client pipe. This will release the related unmanaged resources, but more importantly, will allow the server pipe to disconnect from the client and start waiting for new connections. If the client pipe is not closed the server one will be indefinitely blocked until the Named Pipes server is shut down.
.NET Named Pipes Discussion
|
|
 |