Skip to content Skip to sidebar Skip to footer

Delphi & Datasnap - Connection Timeout, Communicataion Timeout Or A Way To Avoid Client App To Hang When No Server Response

I am trying to use a Client-Server Datasnap based architecture. The client is inside an Android App that connects by Wifi with the Server Program which runs in a PC. This are the s

Solution 1:

I haven't used Firebird yet, but have used TSQLConnection with DataSnap. I assume Firebird uses the same communication libraries as TSQLConnection. If so, then:

The underlying calls are handed off to Windows (i.e., WinSock) and there is no way that I have found to check to see if the connection is still intact.

I wrote a simple DataSnap server-side function called CheckCon(), which does nothing besides give the client app something to call on the server to see if the communication channel is still connected. I put the client-side call to CheckCon() in a try...except block so I could trap the error and auto-reconnect when an EIdSocketError is raised.

The user gets auto-reconnected, which is helpful, but the user still has to wait 30 seconds for the Windows WinSock to timeout before it returns a socket error and the auto-reconnect code executes.

This old thread has an explanation from Remy Lebeau about a similar topic, and since DataSnap uses Indy, I think it applies here too:

You won't be able to [check if the client is still connected to the server] in a timely manner. Indy uses blocking sockets, and blocking sockets simply are not designed to detect abnormal disconnects quickly. When an abnormal disconnect occurs, the underlying socket library (WinSock on Windows, Libc on Linux, etc) will not know that the socket is lost until the library times out internally and then invalidates the socket. Until that happens, there is no way for Indy to know whether the socket is actually connected or not, because the library itself does not know.

Post a Comment for "Delphi & Datasnap - Connection Timeout, Communicataion Timeout Or A Way To Avoid Client App To Hang When No Server Response"