Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
505 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...