简体   繁体   中英

OnDisconnect event on idHttpServer

Is there any event that is fired when the idHttpServer disconnects?

By disconnect I dont mean when a client disconnects, but when the idHTTPServer disconnect for some reason.

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). The idHttpServer.OnDisconnect , according to the help, is only fired when a client disconnects from the server.

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. If Windows tells you this port is not listening, then record this to a log and restart your server. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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