如何测试远程连接(检查状态)

发布于 2024-07-09 01:15:13 字数 118 浏览 8 评论 0原文

我在主机应用程序中创建了一个对象,并且可以使用远程处理远程访问它,有什么方法可以测试连接以确保它仍然“活动”? 也许我可以使用一个在远程连接断开时触发的事件,或者一些可以告诉我远程连接状态的属性。 有这样的东西可用吗?

I have an object created in a host application and can access it remotely using remoting, is there any way I can test the connection to ensure it is still "alive"? Maybe an event I can use that fires if the remoting connection gets disconnected, or some property that can tell me the state of the remoting connection. Is there something like this available?

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

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

发布评论

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

评论(2

ぇ气 2024-07-16 01:15:13

我通常向远程服务器 MarshallByRef 类添加另一个方法,
(我通常将其命名为 Ping(),如:

 public void Ping() {} 

不执行任何操作,也不返回任何内容。然后为了“测试”我的连接,我调用此方法...如果它抛出 System.Net.Sockets.Exception,我有失去了连接......

I generally add another method to the remoting server MarshallByRef class,
(I generally name it Ping(), as in:

 public void Ping() {} 

that does nothing, and returns nothing.. Then to "test" my connection, I call this method... If it throws a System.Net.Sockets.Exception, I have lost the connection....

温暖的光 2024-07-16 01:15:13

检查连接有什么好处? 即使您对它进行 ping 操作,也不意味着在您进行远程调用时连接仍然处于活动状态。

只要尝试/捕捉您的远程呼叫,您就会知道。

这种类型的检查是没有意义的(网络连接、文件锁定等)。 因为您检查的事物的状态可能会在检查后立即发生变化。 你只需托盘,如果失败则清理/重试。

What benefit will you have to check the connection? Even if you ping it, it does not mean that in the next moment the connection will still be alive when you make your remoting call.

Just try/catch you remoting calls and you will know.

This type of checks are meaningless (net connection, file locking, etc.). As the state of the thing you check can change immediately after the check. You just tray, and cleanup/retry if it fails.

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