服务器关闭时通过 NamedPipe 发送数据

发布于 2024-10-04 17:00:44 字数 160 浏览 1 评论 0原文

我想知道如何处理通过命名管道(一个服务器和一个客户端)成功连接两个进程,并且突然(由于某种原因)服务器进程结束的情况。

管道会发生什么情况?关门了吗? 客户端发送到服务器的信息会发生什么情况?它会迷路吗? 客户端如何知道服务器是否宕机了?

祝一切顺利,

吉尔

I was wondering how to handle a situation where you successfully connected two processes through named pipe (one server and one client), and suddenly (for some reason) the server process ends.

What happens to the pipe? Does it close?
What happens to information being sent by the client to the server? Does it get lost?
How can the client know if the server is down?

All The Best,

Gil

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任性一次 2024-10-11 17:00:44

例如,如果您使用 System.IO.Pipes 和 NamedPipeServerStream,当管道损坏或断开连接时,您将收到 IOException。

当您使用 NamedPipeClientStream 从服务器读取信息时,我相信客户端会等待,直到在 NamedPipeClientStream.Connect() 调用替代方案上建立连接,您可以使用 < code>NamedPipeClientStream.Connect(Int32) 选项用于在预定时间段后使连接超时。除此之外,当出现问题时,StreamReader.ReadLine() 还能够抛出 IOException

NamedPipeClientStream.IsConnected 将是确定客户端是否成功连接到服务器或者是否已断开、关闭或损坏的简单方法。

If you are using System.IO.Pipes and NamedPipeServerStream for example, you would get IOException when a pipe is broken or disconnected.

When you are using NamedPipeClientStream for reading in information from server, I believe the client would wait till a connection is established on the NamedPipeClientStream.Connect() call alternative you could use NamedPipeClientStream.Connect(Int32) option to timeout a connection after a predetermined period. Apart from that the StreamReader.ReadLine() is also capable of throwing IOException when something does not go well.

The NamedPipeClientStream.IsConnected would be a simple way to determine if the client is connected successfully to the server or if it is disconnected, closed, or broken.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文