Datasnap:有没有办法检测全局连接丢失?
我正在寻找检测本地连接丢失的情况。 是否有办法做到这一点,就像 Corelabs 组件上的事件一样?
谢谢
编辑: 抱歉,我会尝试更具体: 我目前正在使用 datasnap 2009 设计一个原型。所以我有一个瘦客户端、一个无状态服务器应用程序和一个数据库服务器。
我能够做的是检测和处理客户端和服务器应用程序之间的连接丢失(互联网连接),以适当地处理它,即:向用户显示信息丰富的错误消息或检测服务器关闭以静默重定向另一个应用程序服务器。
在 2 层中,我使用 ODAC 组件来管理该问题,TOraSession 有一些事件来处理此问题。
I'm looking to detect local connection loss. Is there a mean to do that, as with the events on the Corelabs components ?
Thanks
EDIT:
Sorry, I'm going to try to be more specific:
I'm currently designing a prototype using datasnap 2009. So I've got a thin client, a stateless server app and a database server.
What I would be able to do is to detect and handle connection loss (internet connectivity) between the client and the server app to handle it appropriately, ie: Display an informative error message to the user or to detect a server shutdown to silently redirect on another app server.
In 2-tier I used to manage that with ODAC components, the TOraSession have some events to handle this issues.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,连接断开时不会触发事件,除非针对数据库触发了语句。 这是因为除非有某种 is-alive ping 正在进行,否则无法知道连接是否丢失。
许多框架通过对服务器执行非常小的查询来检查连接是否仍然有效。 可能是从服务器获取时间。 特别是在连接池环境中。
您可以在应用程序中的某些数据库事件中(执行之前?)实现连接检查功能。 或者制作一个每 10 秒检查一次的计时器。
Normally there is no event fired when a connection is broken, unless a statement is fired against the database. This is because there is no way of knowing a connection loss unless there is some sort of is-alive pinging going on.
Many frameworks check if a connection is still valid by doing a very small query against the server. Could be getting the time from a server. Especially in a connection pooling environment.
You can implement a connection checking function in your application in some of the database events (beforeexecute?). Or make a timer that checks every 10 seconds.
在客户端上生成一个线程,定期向服务器发送一些 RPC“Ping”或“Heartbeat”命令。
如果失败,客户端知道连接发生了问题
如果服务器在一段时间内不再听到客户端的声音(例如,心跳间隔的两倍),他可以得出结论,客户端已断开连接,但这需要有状态服务器(并且您的设计是无状态的,因此需要在辅助系统中进行事件处理,可以通过消息队列进行馈送)
Spawn a thread on the client which periodically sends some RPC 'Ping' or 'Heartbeat' commands to the server.
if this fails, the client knows that something happened to the connection
if the server does not hear the client anymore for some time period (for example, two times the heartbeat interval), he can conclude that the client disconnected, however this requires a stateful server (and your design is stateless so it would require event processing in a secondary system, which could be fed through a message queue)