代码之家  ›  专栏  ›  技术社区  ›  Hrvoje

Windows Linux命名管道构建-如何从Java应用程序中读取命名管道

  •  0
  • Hrvoje  · 技术社区  · 2 年前

    我在Visual Studio中为linux-x64构建了一个PLC服务器和测试客户端 https://github.com/S7NetPlus/s7netplus

    所有这些都可以在Ubuntu 22.04上运行。PLC服务器创建了一个命名管道,我必须用Java应用程序编写该管道。

    因此,Java应用程序只需要向这个现有的命名管道写入“1”。没有别的。我正在使用以下内容:

    RandomAccessFile pipe = new RandomAccessFile("\\\\.\\pipe\\pipename ", "rw");
                    short sVal = 1;
                    pipe.write((byte) sVal);
    

    但服务器在从Java编写时不会更改pipename的状态。

    我在谷歌上搜索了一遍,像线一样 this 类似的,但对于初学者来说,我无法在我的Ubuntu中找到这个命名管道的位置? 所以这部分困扰着我 "\\\\.\\pipe\\pipename " 这可能是不正确的,但我不明白如何在Java中查找和引用命名管道。

    管道肯定存在于Ubuntu上,因为PLC服务器和测试客户端工作正常。

    编辑

    因此,当运行PLC服务器时,我可以找到服务器进程正在写入的所有进程。服务器进程正在实现两个管道:

    userjo@UBUNTU-VM:~$ sudo ls -l /proc/428576/fd
    total 0
    lrwx------ 1 root root 64 stu  23 08:56 0 -> /dev/pts/6
    lrwx------ 1 root root 64 stu  23 08:56 1 -> /dev/pts/6
    lrwx------ 1 root root 64 stu  23 08:58 10 -> 'socket:[85449454]'
    lr-x------ 1 root root 64 stu  23 08:58 12 -> 'pipe:[85449455]'
    l-wx------ 1 root root 64 stu  23 08:58 13 -> 'pipe:[85449455]'
    lr-x------ 1 root root 64 stu  23 08:58 14 -> /home/userjo/plc/plcserver/userjoplcserver.dll
    lr-x------ 1 root root 64 stu  23 08:58 15 -> /home/userjo/plc/plcserver/userjoplcserver.dll
    lr-x------ 1 root root 64 stu  23 08:58 16 -> /home/userjo/plc/plcserver/System.Runtime.dll
    lr-x------ 1 root root 64 stu  23 08:58 17 -> /home/userjo/plc/plcserver/System.Console.dll
    lr-x------ 1 root root 64 stu  23 08:58 18 -> /home/userjo/plc/plcserver/System.Threading.Thread.dll
    lr-x------ 1 root root 64 stu  23 08:58 19 -> /home/userjo/plc/plcserver/System.Threading.Tasks.dll
    lrwx------ 1 root root 64 stu  23 08:56 2 -> /dev/pts/6
    lr-x------ 1 root root 64 stu  23 08:58 20 -> /home/userjo/plc/plcserver/System.Runtime.Extensions.dll
    lr-x------ 1 root root 64 stu  23 08:58 21 -> /home/userjo/plc/plcserver/System.Threading.dll
    lrwx------ 1 root root 64 stu  23 08:58 22 -> /dev/pts/6
    lr-x------ 1 root root 64 stu  23 08:58 23 -> /home/userjo/plc/plcserver/System.Collections.dll
    lr-x------ 1 root root 64 stu  23 08:58 24 -> /home/userjo/plc/plcserver/System.Text.Encoding.Extensions.dll
    lr-x------ 1 root root 64 stu  23 08:58 25 -> /dev/urandom
    lr-x------ 1 root root 64 stu  23 08:58 26 -> /home/userjo/plc/plcserver/S7.Net.dll
    lr-x------ 1 root root 64 stu  23 08:58 27 -> /home/userjo/plc/plcserver/System.IO.Pipes.dll
    lr-x------ 1 root root 64 stu  23 08:58 28 -> /home/userjo/plc/plcserver/System.Net.Sockets.dll
    lr-x------ 1 root root 64 stu  23 08:58 29 -> /home/userjo/plc/plcserver/S7.Net.dll
    lr-x------ 1 root root 64 stu  23 08:56 3 -> 'pipe:[85449450]'
    lr-x------ 1 root root 64 stu  23 08:58 30 -> /home/userjo/plc/plcserver/netstandard.dll
    lr-x------ 1 root root 64 stu  23 08:58 31 -> /home/userjo/plc/plcserver/System.Net.Primitives.dll
    lr-x------ 1 root root 64 stu  23 08:58 32 -> /home/userjo/plc/plcserver/Microsoft.Win32.Primitives.dll
    lr-x------ 1 root root 64 stu  23 08:58 33 -> /home/userjo/plc/plcserver/System.Diagnostics.Tracing.dll
    lrwx------ 1 root root 64 stu  23 08:58 34 -> 'socket:[85448469]'
    lrwx------ 1 root root 64 stu  23 08:58 35 -> 'socket:[85452277]'
    lr-x------ 1 root root 64 stu  23 08:58 36 -> /home/userjo/plc/plcserver/System.Memory.dll
    lr-x------ 1 root root 64 stu  23 08:58 37 -> /home/userjo/plc/plcserver/System.Threading.ThreadPool.dll
    lr-x------ 1 root root 64 stu  23 08:58 38 -> /home/userjo/plc/plcserver/System.Collections.Concurrent.dll
    lrwx------ 1 root root 64 stu  23 08:58 39 -> 'anon_inode:[eventpoll]'
    l-wx------ 1 root root 64 stu  23 08:58 4 -> 'pipe:[85449450]'
    lr-x------ 1 root root 64 stu  23 08:58 40 -> 'pipe:[85452278]'
    l-wx------ 1 root root 64 stu  23 08:58 41 -> 'pipe:[85452278]'
    lrwx------ 1 root root 64 stu  23 08:58 42 -> 'socket:[85454101]'
    lr-x------ 1 root root 64 stu  23 08:58 43 -> /home/userjo/plc/plcserver/System.Runtime.InteropServices.dll
    lrwx------ 1 root root 64 stu  23 08:58 44 -> 'socket:[85449498]'
    lrwx------ 1 root root 64 stu  23 08:58 45 -> 'socket:[85452306]'
    lr-x------ 1 root root 64 stu  23 08:58 46 -> 'pipe:[85453000]'
    l-wx------ 1 root root 64 stu  23 08:58 47 -> 'pipe:[85453000]'
    lrwx------ 1 root root 64 stu  23 08:56 5 -> /dev/pts/6
    lrwx------ 1 root root 64 stu  23 08:58 6 -> /dev/pts/6
    lrwx------ 1 root root 64 stu  23 08:58 7 -> /dev/pts/6
    lr-x------ 1 root root 64 stu  23 08:58 9 -> /home/userjo/plc/plcserver/System.Private.CoreLib.dll
    

    问题是,我应该从Java中向哪个管道进行编写,以及如何引用它?

    0 回复  |  直到 2 年前