Since FB did not implement the connectiontimeout property of the
FbConnection, I neeeded a way to get around the @30 second delay when
connection to a FB server. Below is my solution.
using System.Net;
using System.Net.Sockets;
using System.Configuration;

private bool TestPort(string address, int port)
{
    int timeout = 500;
    if(ConfigurationManager.AppSettings["RemoteTestTimeout"]
!= null)
        timeout =
int.Parse(ConfigurationManager.AppSettings["RemoteTestTimeout"]);
    var result = false;
    try
    {
        using(var socket = new
Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
        {
            IAsyncResult
asyncResult = socket.BeginConnect(address, port, null, null);
            result
= asyncResult.AsyncWaitHandle.WaitOne(timeout, true);
            socket.Close();
        }
        return result;
    }
    catch { return false; }
}
This method tries to open a tcp connection to the FB server and if
successful, immediately returns, otherwise it waits until the timeout
specified and then returns. Just make the call using the servername or ip of
the FB server, with the port. Just make sure the timeout you specify is
tuned to your own network speed, or you may receive false negatives.
Hope this helps others who are frustrated by the lack of a timeout.




--
View this message in context: 
http://firebird.1100200.n4.nabble.com/Checking-if-FireBird-Server-is-running-tp4633459.html
Sent from the firebird-net-provider mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to