检测到机器是否已连接/可用?

发布于 2024-10-24 01:18:54 字数 103 浏览 2 评论 0原文

如何检测机器在当前网络中是否已连接/可用。

当然,它有多种用途,但我主要担心的是,我的应用程序使用位于特定计算机中的资源,如果它们不可用,它甚至不会尝试连接,而是使用本地资源。

How can I detect if a machine is connected/available in the present network.

It has several uses of course, but my main concern here is that my application uses resources located in specific machines and if they are not available it will not even attempt the connection and will use local resources.

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

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

发布评论

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

评论(4

孤独岁月 2024-10-31 01:18:55

与尝试连接不同的策略:让服务器通过中间件(管道?)发送 UDP 广播或某种心跳信号来告诉客户端服务是否仍然可用,客户端会监听这些信号 - 发布/订阅通信模型。

A different strategy than trying to connect: let the server tell the clients if the services are still available, by sending UDP Broadcast or some kind of heartbeat signal over middleware (pipes?), which the clients listens to - a publish/subscribe communication model.

恋竹姑娘 2024-10-31 01:18:54

你可以尝试对机器进行 ping 操作。查看这篇文章 使用 Delphi 进行 PING和 WMI

you can try making a ping to the machine. check this article Making a PING with Delphi and the WMI.

一场春暖 2024-10-31 01:18:54

ICMP 回显请求 (PING) 将告诉您计算机是否已启动并且可以通过网络访问。它不会告诉您要连接的服务在计算机上是否可用(已启动并正在运行)。

最好的选择可能是只尝试连接,如果连接失败,则回退到本地资源。

ICMP echo request (PING) will tell you if the machine is up and reachable on the network. It will not tell you if the service you want to connect to is available on the machine (up and running).

Best bet would probably be to just attempt the connection and fall back to local resources if the connection fails.

神回复 2024-10-31 01:18:54

只需尝试使用该资源,如果出现错误,请改用本地资源。您尝试实现的策略存在几个问题,包括测试和使用之间的时间窗口,在此期间资源可能变得不可用,并且实际上并没有测试资源的可用性,仅测试某些资源的可用性低阶事物,例如 TCP 端口或堆栈的 ICMP 回显部分。一般来说,检测资源是否可用的最佳方法就是尝试使用它并从故障中恢复。无论如何,您都必须编写代码来处理这些故障,为什么要这样做两次呢?

Just try to use the resource and if you get an error use the local resource instead. The strategy you are trying to implement suffers from several problems including timing windows between the test and the use, during which the resource may become unavailable, and also doesn't actually test the resource for availability, only some lower-order thing like a TCP port or the ICMP echo part of the stack. In general the best way to detect whether a resource is available is just to try to use it, and recover from the failures. You have to write code to handle those failures anyway, why do it all twice?

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