简体   繁体   English

idHttpServer上的OnDisconnect事件

[英]OnDisconnect event on idHttpServer

Is there any event that is fired when the idHttpServer disconnects? idHttpServer断开连接时是否触发任何事件?

By disconnect I dont mean when a client disconnects, but when the idHTTPServer disconnect for some reason. 断开连接不是指客户端断开连接,而是idHTTPServer由于某种原因断开连接。

I can explain it better: when idHTTPServer is listening to a socket port and, for some unknown reason, the computer disconnects from the network (lets say, for example, that the the network becomes unavailable) the component does not work anymore (it stops listening to the port) and, in that case, I need to reconnect (reopen the port). 我可以更好地解释一下:当idHTTPServer正在侦听套接字端口时,由于某种未知原因,计算机断开了与网络的连接(例如,说网络变得不可用),该组件不再起作用(停止了)监听端口),在这种情况下,我需要重新连接(重新打开端口)。 The idHttpServer.OnDisconnect , according to the help, is only fired when a client disconnects from the server. 根据帮助,仅当客户端与服务器断开连接时才触发idHttpServer.OnDisconnect

You could consider creating a watchdog connection to your server from its self connecting on an interval, when you were unable to connect you would then restart you server or whatever you need to do to correct the issue. 您可以考虑每隔一段时间从其自身连接创建到服务器的看门狗连接,如果无法连接,则可以重新启动服务器或执行任何操作来纠正此问题。

This does have the added bonus that you are actually testing the connection to you server so if any other issue happen that may cause client issues connection these will be picked up to. 这确实具有额外的好处,您实际上正在测试与服务器的连接,因此,如果发生任何其他可能导致客户端问题连接的问题,这些问题将得到解决。

This could also be done is a separate application which has the ability to close, kill and restart you server 这也可以通过一个单独的应用程序来完成,该应用程序可以关闭,终止和重新启动服务器

I have two suggestions to help you solve your issue. 我有两条建议可以帮助您解决问题。

First of all, add a timer where once every minute (or interval of your choice), "ask" windows if your port is still listening or not. 首先,添加一个计时器,该计时器每分钟(或您选择的间隔)一次,如果端口仍在侦听,则“询问”窗口。 This must be done outside of Indy, as Indy has no mechanism to do this. 这必须在Indy之外完成,因为Indy没有机制可以执行此操作。 If Windows tells you this port is not listening, then record this to a log and restart your server. 如果Windows告诉您该端口未监听,则将其记录到日志中并重新启动服务器。 Check this log periodically to see if your app has ever reported your port to stop listening. 定期检查此日志,以查看您的应用是否曾经报告过您的端口以停止监听。 This will tell you if it really is disconnecting or not. 这将告诉您它是否确实断开连接。

Second of all, you might want to consider a nightly restart of your server socket. 第二,您可能需要考虑每晚重新启动服务器套接字。 For example, at midnight every night, stop and start the server socket to ensure a fresh connection. 例如,在每晚的午夜,停止并启动服务器套接字以确保重新连接。 There might be some variable overflow, for example, if you are constantly incrementing a number and it keeps getting larger and larger, then over time, that number will become too large for your application to hold it. 可能会有一些变量溢出,例如,如果您不断增加一个数字,并且这个数字越来越大,那么随着时间的流逝,该数字将变得太大,以至于应用程序无法容纳它。 This can happen anywhere between 5 seconds or 5 months of run-time, depending on how fast you increment it. 运行时间可能在5秒钟或5个月之间的任何时间,具体取决于您递增的速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM