C#Unity3d NamedPipe和Java

问题描述

我将Java用作名为pipe的服务器,并编写了以下代码

 final int MAX_BUFFER_SIZE=1024;

        String    pipeName="\\\\.\\pipe\\testpipe";
        HANDLE hNamedPipe = Kernel32.INSTANCE.CreateNamedPipe(pipeName,WinBase.PIPE_ACCESS_DUPLEX,// dwOpenMode
                WinBase.PIPE_TYPE_MESSAGE | WinBase.PIPE_READMODE_MESSAGE | WinBase.PIPE_WAIT,// dwPipeMode
                1,// nMaxInstances,MAX_BUFFER_SIZE,// nOutBufferSize,// nInBufferSize,(int) TimeUnit.SECONDS.toMillis(30L),// nDefaultTimeOut,null    // lpSecurityAttributes
        );


        while (true) {
            String expMessage = Thread.currentThread().getName() + " says hello";
            byte[] expData = expMessage.getBytes();
            IntByReference lpNumberOfBytesWritten = new IntByReference(0);
            Kernel32.INSTANCE.WriteFile(hNamedPipe,expData,expData.length,lpNumberOfBytesWritten,null);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printstacktrace();
            }
        }

然后在C#中,我正在使用namedpipe客户端流

 using (var pipeClient = new NamedPipeClientStream(".","testpipe",PipeDirection.In))
        {
            if (!pipeClient.IsConnected) { pipeClient.Connect(); }
            using (var reader = new StreamReader(pipeClient))
            {
                using (var writer = new StreamWriter(pipeClient))
                {
                    var running = true;
                    while (running)
                    {
                        var message = reader.ReadLine();
                        if (message != null)
                        {
                            switch (message)
                            {
                                case "Do you accept (y/n):":
                                    writer.WriteLine("y");
                                    writer.WriteLine("quit");
                                    writer.Flush();
                                    break;
                                case "quit":
                                    running = false;
                                    break;
                            }
                        }
                    }
                }
            }
        }

我从C#Unity3D收到错误消息,指定的路径无效。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...