[英]working with fifo data on linux using dotnet core
I would like to use Linux's fifo-like stream on disk (created by using mkfifo) with C# code (dotnet core).我想在磁盘上使用 Linux 的类似 fifo 的 stream(使用 mkfifo 创建)和 C# 代码(dotnet 核心)。 I am looking for examples with using data on disk but I have trouble with finding ones.
我正在寻找使用磁盘上数据的示例,但我很难找到。
I would like to make some modifications of fifo data on disk (eg first.raw) and using another tool/task (written in dotnet core) read that fifo and make an another modification and send it to another fifo data (eg second.raw) and finally by using third tool/task read that second.raw data modify it and send to another fifo data (eg third.raw) to read it by another tool.我想对磁盘上的fifo数据(例如first.raw)进行一些修改,并使用另一个工具/任务(用dotnet core编写)读取该fifo并进行另一次修改并将其发送到另一个fifo数据(例如second.raw ) 最后通过使用第三个工具/任务读取 second.raw 数据对其进行修改并发送到另一个 fifo 数据(例如third.raw)以由另一个工具读取它。
Is it possible using dotnet core on Linux?是否可以在 Linux 上使用 dotnet 核心? Is there any correct way to do that on Linux (queue, named pipes)?
在 Linux (队列,命名管道)上是否有任何正确的方法可以做到这一点?
EDIT编辑
When I am doing this on Ubuntu 18.04 (before running: mkfifo fifoStream.pipe):当我在 Ubuntu 18.04 上执行此操作时(运行之前:mkfifo fifoStream.pipe):
FileStream fs = File.OpenWrite( "fifoStream.pipe" );
using (var sw = new StreamWriter(fs))
{
sw.WriteLine("first line");
sw.Flush();
}
fs.Close();
and running code it hang up and I have to use ctrl+c to stop execution of the app.并运行代码挂断,我必须使用 ctrl+c 来停止应用程序的执行。
I found a solution for Ubuntu 18.04.我找到了 Ubuntu 18.04 的解决方案。 As per: https://johnkoerner.com/csharp/IPC-in-net-core-using-protobuf/ This works for my case:
根据: https://johnkoerner.com/csharp/IPC-in-net-core-using-protobuf/这适用于我的情况:
first running "server" code:首先运行“服务器”代码:
static void Main(string[] args)
{
Console.WriteLine("Starting Server");
var pipe = new NamedPipeServerStream("fifoStream.pipe", PipeDirection.InOut);
Console.WriteLine("Waiting for connection....");
pipe.WaitForConnection();
Console.WriteLine("Connected");
pipe.WriteByte(66);
pipe.Disconnect();
}
then running "client" code:然后运行“客户端”代码:
static void Main(string[] args)
{
Console.WriteLine("Starting Client");
var pipe = new NamedPipeClientStream(".", "fifoStream.pipe", PipeDirection.InOut, PipeOptions.None);
Console.WriteLine("Connecting");
pipe.Connect();
pipe.ReadByte(); //here I receive byte 66
Console.WriteLine("Done");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.