views:

4212

answers:

5

What is the correct way to setup a named pipe in C# across a network?

Currently I have two machines, 'client' and 'server'.

Server sets up its pipe in the following manner:

NamedPipeServerStream pipeServer = new NamedPipeServerStream(
    "pipe",
    PipeDirection.InOut,
    10,
    PipeTransmissionMode.Byte,
    PipeOptions.None)
pipeServer.WaitForConnection();
//... Read some data from the pipe

The client sets up its connection in the following manner:

NamedPipeClientStream pipeClient = new NamedPipeClientStream(
    "server",
    "pipe",
    PipeDirection.InOut);
pipeClient.Connect(); //This line throws an exception
//... Write some data to the pipe

The 'server' machine can be accessed on the network by going to "\\server".

Whenever I run the program, I get a System.UnauthorizedAccessException that says "Access to the path is denied." The code works fine when I run the server and client on my local machine and attempt to connect to "." with the client.

A: 

Look in the System.Runtime.Remoting namespace. IIRC, named pipes are one option for the protocol used by remoting channels.

Joel Coehoorn
I'm not sure what I should be looking for...
Anton
+1  A: 

have you tried to set PipeTransmissionMode.Message on the server?

Yes, but it still does not work.
Anton
+2  A: 

You need to set permissions on the NamedPipeServerStream so that the client will have permissions to access the pipe.

I would look at the SetAccessControl method of your NamedPipeServerStream.

duckworth
A: 

It is not possible to used named pipes between machines.

"The WCF-NetNamedPipe adapter provides cross-process communication on the same computer"

http://msdn.microsoft.com/en-us/library/bb226493.aspx

Shiraz Bhaiji
This is Bizz Server, not Windows doc.http://msdn.microsoft.com/en-us/library/aa365590(VS.85).aspx states that it should work!
weismat
That may be a WCF limitation. Named pipes in Windows (like the one the person is asking about) can work across networks. From: http://msdn.microsoft.com/en-us/library/system.io.pipes.namedpipeserverstream.aspx"Named pipes can be used for interprocess communication locally or over a network" There are some limitations - Local lans only (so the moment you hit a router it stops) - Older versions of Windows (like 2000) limit to 10 connections - Anonymous pipes are single machine only
Robert MacLean
A: 

I am having issues with Named pipes.

The following is the scenario. I have 2 winform applications, app1 and app2. One consist of a textbox and a button and another application has just a list box. The idea is to type some text in app-1, press a button to send the text and it should populate the list box of app2.

i am using sw.Write(textbox1.text) to write to the pipe. it does'nt populate the listbox of app2. But if i close streamwriter using sw.close(), it immediately writes the string to listbox. BUT, sw.close also closes the pipe since the sw is created using the pipe like sw = new streamwriter(pipe);

Does this mean whenever i want to send a message i need to create a new pipeserver and write to pipe and close. Can I not open a pipe once and keep dumping messages inside whenever i want and close it when the application closes?

Rao