0

I've built a PLC server and test client for linux-x64 in Visual Studio with https://github.com/S7NetPlus/s7netplus

All run OK on Ubuntu 22.04. The PLC server created a named pipe which I have to write to with the Java app.

So the Java app will only have to write "1" to this existing named pipe. Nothing else. I'm using something like:

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

But the server is not changing status of pipename when writing from Java.

I googled all over ,thread like this and similar but for starters I'm unable to locate where this named pipe lives in my Ubuntu? So this part is troubling me "\\\\.\\pipe\\pipename " This is probably incorrect but I don't understand how to find and reference named pipe in Java.

The pipe is definitely existing on Ubuntu since the PLC server and test client are working OK.

EDIT

So when running PLC server I can find all processes to which the server process is writing. The server process is implementing 2 pipes:

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

The question is - which one is the pipe I'm supposed to write to from Java and how to reference it?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Hrvoje
  • 13,566
  • 7
  • 90
  • 104
  • 1
    `\\\\.\\pipe\\pipename` is a thing on Windows, which has named pipes in a different namespace. Obviously you'll need to use the Linux named pipe if you're on Linux. Not to mention the trailing space may give you trouble. Also never use paths that way, always use [verbatim string](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/#verbatim-string-literals) like `@"\\.\pipe\pipename"` or raw string literal like `"""\\.\pipe\pipename"""` for readability – phuclv Nov 23 '22 at 02:25
  • @phuclv space is error. I just use "@pipename" in windows that pipe ends up in \\.\pipe\pipename on Windows as you said but where do I find it when I build that and deploy on Linux? – Hrvoje Nov 23 '22 at 05:22
  • on Linux everything is just files, including special files like sockets or named pipes. So you can just create the pipe file anywhere, typically /tmp – phuclv Nov 23 '22 at 07:21
  • @phuclv I know that but this is Windows .NET app built for linux-64, I got to find pipe which this process is creating on Ubuntu. See my edit - I manage to find all processes that are writting something in Ubuntu. I see references to pipe files but don't know which is right one to use with Java... – Hrvoje Nov 23 '22 at 08:09
  • .NET Core is a cross-platform framework. So it's not *Windows .NET* but **.NET** only. Those file descriptors have nothing to do with "writing process", they're simply files that the process is opening. You said the test client is working but what are they? How do they work – phuclv Nov 23 '22 at 14:10
  • `which one is the pipe` who knows? You're the one who created the pipe with the server, why don't you know its name? You must have a name when you create the pipe, exactly like when you create any other files – phuclv Nov 23 '22 at 14:14
  • 2
    .NET named pipes are apparently implemented via sockets for Linux (rather than via named pipes, which are a related but distinct concept in POSIX); see https://github.com/dotnet/runtime/issues/14633. So in your Java application you'll want to use sockets rather than file IO. Or I guess you could try to read the socket FD as a file in Java but I have no idea whether/how that would work. – Konrad Rudolph Nov 23 '22 at 14:25
  • Thank you @KonradRudolph , that gives answers to a lot of the issues we where facing. – Hrvoje Nov 24 '22 at 02:25

0 Answers0