How to check the availability of a firebird server? lazarus / 16-Databases ---------------------------------------------------------------------- Mando · 2012-03-13 11:14 Hello all: I've a problem. My application with firebird was working perfectly until this morning. For some reason, the server that runs on another computer, has left to serve. Then when my application tries to connect, it takes a lot to say you can not. Is there any way of knowing whether the server will attempt to connect before the connection? (A way faster, of course). Using Win XP (client) / Win 7 (server) + Lazarus 0.9.31 + Zeos 7-dev (codeTyphon) + firebird 2.1 Regards. ---------------------------------------------------------------------- BigChimp · 2012-03-13 12:00 Not really, that I know of. You might look into using the services port/API. You could of course also first ping the server to see if it is up - but the server or a firewall might block the pings, so that is not too reliable either. You could just send something to the regular Firebird port (e.g. tcp 3050) and see if you get something back... but that's basically what the client does, too. There might be a way to set the client timeout a bit shorter, which may help. Don't know if that is possible or how that should be done... ---------------------------------------------------------------------- Mando · 2012-03-13 12:16 Thanks for your answer: I tried try to connect with server via a TClientSocket, with port 3050. This is the result: (if server fails) With socket: 21.94 s With zconnection: 44.75 s I can't chage the timeout  of any of the two components. If server connects: With socket: 109 ms With zconnection: 422 ms ---------------------------------------------------------------------- ludob · 2012-03-13 13:51 You can use non-blocking sockets to check if a server is on line (uses blcksock from synapse library): Code: [Select]function IsConnected(ip,port:string;delay:integer):boolean; var   sock:TTCPBlockSocket; begin   result:=false;   sock:=TTCPBlockSocket.create;   try     sock.NonBlockMode:=true;     sock.Connect(ip,port);     sleep(delay);     sock.SendString(#0);     result:=sock.LastError=0;     sock.CloseSocket;   finally     sock.free;   end; end; Above code will send a null character to the destination. If the connection is not established in delay milliseconds, a WSAENOTCONN error will be returned and the function fails. ---------------------------------------------------------------------- Mando · 2012-03-13 15:34 Thanks ludob: It works fine.