服务器关闭时通过 NamedPipe 发送数据
我想知道如何处理通过命名管道(一个服务器和一个客户端)成功连接两个进程,并且突然(由于某种原因)服务器进程结束的情况。
管道会发生什么情况?关门了吗? 客户端发送到服务器的信息会发生什么情况?它会迷路吗? 客户端如何知道服务器是否宕机了?
祝一切顺利,
吉尔
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如,如果您使用 System.IO.Pipes 和 NamedPipeServerStream,当管道损坏或断开连接时,您将收到 IOException。
当您使用
NamedPipeClientStream
从服务器读取信息时,我相信客户端会等待,直到在NamedPipeClientStream.Connect()
调用替代方案上建立连接,您可以使用 < code>NamedPipeClientStream.Connect(Int32) 选项用于在预定时间段后使连接超时。除此之外,当出现问题时,StreamReader.ReadLine()
还能够抛出IOException
。NamedPipeClientStream.IsConnected
将是确定客户端是否成功连接到服务器或者是否已断开、关闭或损坏的简单方法。If you are using
System.IO.Pipes
andNamedPipeServerStream
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 theNamedPipeClientStream.Connect()
call alternative you could useNamedPipeClientStream.Connect(Int32)
option to timeout a connection after a predetermined period. Apart from that theStreamReader.ReadLine()
is also capable of throwingIOException
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.