Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何让运行在不同主机上的两个进程通过命名管道进行通信_C#_.net_Named Pipes - Fatal编程技术网

C# 如何让运行在不同主机上的两个进程通过命名管道进行通信

C# 如何让运行在不同主机上的两个进程通过命名管道进行通信,c#,.net,named-pipes,C#,.net,Named Pipes,我使用命名管道让运行在不同主机上的两个进程进行通信。 以下是服务器代码: public class PipeServer { public static void Main() { PipeSecurity ps = new PipeSecurity(); ps.AddAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.FullControl,

我使用命名管道让运行在不同主机上的两个进程进行通信。 以下是服务器代码:

public class PipeServer
{
    public static void Main()
    {
        PipeSecurity ps = new PipeSecurity();
        ps.AddAccessRule(new PipeAccessRule("Everyone",
            PipeAccessRights.FullControl,
            System.Security.AccessControl.AccessControlType.Allow));

        NamedPipeServerStream pipeServer = new NamedPipeServerStream(
           "testpipe", PipeDirection.InOut, 4,
           PipeTransmissionMode.Message, PipeOptions.WriteThrough,
           1024, 1024, ps);

        StreamReader sr = new StreamReader(pipeServer);
        StreamWriter sw = new StreamWriter(pipeServer);

        do {
            try {
                pipeServer.WaitForConnection();
                sw.WriteLine("Waiting");
                sw.Flush();
                pipeServer.WaitForPipeDrain();
                string message = sr.ReadLine();
                sw.WriteLine("got message " + message);
            } catch (Exception ex) { throw ex; } finally {
                pipeServer.WaitForPipeDrain();
                if (pipeServer.IsConnected) { pipeServer.Disconnect(); }
            }
        } while (true);
    }
}
。。。以下是客户端代码:

public class PipeClient
{
    static void Main(string[] args) {
        NamedPipeClientStream pipeClient = new NamedPipeClientStream(
            "10.225.154.59", "testpipe",
            PipeDirection.InOut, PipeOptions.None,
            TokenImpersonationLevel.None);

        if (pipeClient.IsConnected != true) { pipeClient.Connect(); }

        StreamReader sr = new StreamReader(pipeClient);
        StreamWriter sw = new StreamWriter(pipeClient);

        string temp;
        temp = sr.ReadLine();

        if (temp == "Waiting") {
            try {
                sw.WriteLine("Hello");
                sw.Flush();
                pipeClient.Close();
            } catch (Exception ex) { throw ex; }
        }
    }
}
在远程主机上启动
PipeServer
后,我在工作站上运行客户端。。。但我总是收到以下错误消息:

Unhandled Exception: System.IO.IOException: Logon failure: unknown user name or bad password.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Pipes.NamedPipeClientStream.Connect(Int32 timeout)
at System.IO.Pipes.NamedPipeClientStream.Connect()
PipeClient.Program.Main(String[] args) in G:\My Projects\Lab\NamePipes\Program.cs:line 18
在远程主机上运行
PipeServer
的用户与在我的工作站上运行
PipeClient
的用户不同。。。但这不应该是一个问题,因为我已经添加了正确的访问规则

我错过什么了吗

编辑
阿列克谢建议的一些附加信息。运行服务器的用户是本地管理员,而运行客户端的用户是域用户。有没有一种方法可以让任何人向服务器发送消息?

您缺少有关用户是域帐户还是本地帐户以及客户端帐户是否可以访问服务器机器的信息。伙计,您正在重新发明轮子。相信我,使用WCFJust更新我的帖子,提供更多信息。