我想問你如何設置從遠程客戶端訪問我的命名管道服務器。到目前爲止,我認爲NamedPipes只能用於同一臺計算機上的進程間通信,但基於http://msdn.microsoft.com/en-us/library/windows/desktop/aa365150%28v=vs.85%29.aspx,應該可以通過設置PIPE_ACCEPT_REMOTE_CLIENTS/PIPE_REJECT_REMOTE_CLIENTS來允許/不允許從遠程計算機訪問。我沒有找到如何在.NET中設置此功能的簡單方法。我想PipeSecurity可能會以某種方式用於它,但我沒有找到一個簡單的方法。允許從遠程客戶端訪問命名管道服務器
我目前的解決方案允許所有用戶訪問我在當前機器上的命名管道。有人可以改進我的解決方案,以允許從另一臺機器訪問嗎?
謝謝。
public NamedPipeServerStream CreateNamedPipeServer(string pipeName)
{
const int BufferSize = 65535;
var pipeSecurity = new PipeSecurity();
pipeSecurity.AddAccessRule(new PipeAccessRule("Users", PipeAccessRights.ReadWrite, AccessControlType.Allow));
pipeSecurity.AddAccessRule(new PipeAccessRule("Administrators", PipeAccessRights.ReadWrite, AccessControlType.Allow));
return new NamedPipeServerStream(pipeName, PipeDirection.InOut, countOfServerInstancesToCreate, PipeTransmissionMode.Message, PipeOptions.Asynchronous,
BufferSize,
BufferSize);
}
我想指出,允許從計算機A訪問NamedPipeServer運行的計算機B並非易事。請參閱http://stackoverflow.com/questions/719353/win32-named-pipes-and-remote-clients以獲取更多信息 – user2126375 2014-10-04 19:23:08