管道的另一端没有进程-JAVA中的命名管道

问题描述 投票:1回答:1

我在与Evolis KC200打印机通信时使用此代码:

@Test
public void studyPipe() {
    try {
        String echoText = " {\"id\":\"1\",\"jsonrpc\":\"2.0\",\"method\":\"CMD.GetStatus\",\"params\":{\"device\":\"Evolis KC200\"}}";

        System.out.println("CMD.GetStatus Request: " + echoText);

        String pipeName = "\\\\.\\pipe\\EspfServer00";
        RandomAccessFile pipe = new RandomAccessFile(pipeName, "rw");

        System.out.println("Writing in pipe: " + echoText + " in pipe "
                + pipeName);
        pipe.write(echoText.getBytes("UTF-8"));
        // Thread.sleep(1000);
        String echoResponse = pipe.readLine();
        System.out.println("Response: " + echoResponse);
        pipe.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

但是我得到的只是这个:

java.io.IOException: No process is on the other end of the pipe
    at java.io.RandomAccessFile.read0(Native Method)
    at java.io.RandomAccessFile.read(RandomAccessFile.java:330)
    at java.io.RandomAccessFile.readLine(RandomAccessFile.java:939)
    at 

他们有一个基于另一种语言(C#)构建的测试工具,其命名管道客户端如下所示:我的JAVA代码中缺少什么?

 public static string SendRequestPipe(string ip, string port, string request)
        {
            NamedPipeClientStream objPipeClient;

            string answer = string.Empty;

            objPipeClient = new NamedPipeClientStream(ip, port, PipeDirection.InOut);
            try
            {
                // Connexion au named pipe ou attente de la disponibilité du named pipe
                objPipeClient.Connect(1000);     

                // Paramétrage de la connexion
                objPipeClient.ReadMode = PipeTransmissionMode.Message;               

                if (objPipeClient.IsConnected == true)
                {
                    // Send request
                    byte[] datain = Encoding.UTF8.GetBytes(request);
                    objPipeClient.Write(datain, 0, datain.Length);

                    // Get answer
                    int recv = 0;
                    byte[] data = new byte[1024];

                    do
                    {
                        recv = objPipeClient.Read(data, 0, data.Length);
                        answer += Encoding.UTF8.GetString(data, 0, recv);                        
                    } while (!objPipeClient.IsMessageComplete);
                }
            }
            catch (Exception ex)
            {                      

            }
            finally
            {
                objPipeClient.Close();
                objPipeClient.Dispose();
            }

            return answer;
        }

我也在Java中尝试了类似的方法,但是遇到了同样的错误。

UPDATE:

我想我已经知道了这个问题,但是我仍然没有解决方案。似乎JAVA代码正在创建PIPE的另一个实例,这就是为什么它未在该新实例上接收任何进程的原因。我使用C#代码进行了测试,但没有创建新实例。

我使用此工具检查了实例:https://docs.microsoft.com/en-us/sysinternals/downloads/pipelist

java named-pipes
1个回答
-1
投票

我也面临同样的问题,您找到任何解决方案了吗?我正在使用Evolis打印机KM500B。

© www.soinside.com 2019 - 2024. All rights reserved.