简体   繁体   English

Quickfix / n-没有连接超时事件或找不到主机?

[英]Quickfix/n - No event for connection timeout or host not found?

So I have a project where I need to create failover between two FIX quote hosts in case of failure. 因此,我有一个项目,在发生故障的情况下,我需要在两个FIX引用主机之间创建故障转移。

The FixApplication (IApplication) OnLogout() is nice to hook an event to when a socket is dropped or you are logged out. FixApplication(IApplication)OnLogout()可以很好地将事件挂接到套接字丢失或注销时。 This is simple. 这很简单。 But this only works if the socket connection was successful to start off with. 但这仅在套接字连接成功开始时有效。

If you start up the application and the host is down, no method is actually called for this anywhere. 如果启动应用程序且主机已关闭,则实际上在任何地方都不会调用任何方法。 Not in IApplication, nor in the socket IInitiator. 不在IApplication中,也不在套接字IInitiator中。 No error is thrown anywhere either, the QuickFix initiator will simply just silently retry. 也不会在任何地方引发错误,QuickFix启动器将只是默默地重试。

I am using a Timer with a callback right now to manually poll every so often and check if Initiator IsLoggedOn() is false. 我现在使用带有回调的Timer来频繁地手动轮询,并检查Initiator IsLoggedOn()是否为false。 Then triggering a failover. 然后触发故障转移。

But this is really clunky and not elegant. 但是,这确实很笨拙,并不优雅。

Is there any other event or method I can hook into to receive the notice for socket network failures BEFORE a network connection and session is established successfully? 在成功建立网络连接和会话之前,我还有其他事件或方法可以挂接到套接字网络故障通知中吗?

Thanks! 谢谢!

Timer t = new Timer(5000) 
t.Elapsed += CheckSocketConnected;
private void CheckSocketConnected(object source, ElapsedEventArgs e)
{
     var connected = socketInitiator.IsLoggedOn;
     if (!connected)
     {
         SwitchToAlternateProvider();
     }
}

Well, after realising the limitation of the QuickFix/N component, I would never receive any feedback from this library if the host was down. 好吧,在意识到QuickFix / N组件的局限性之后,如果主机关闭,我将永远不会从该库收到任何反馈。

My resolution was to just simply use the following piece of code to check if socket was open before starting the connection in QuickFix/n 我的解决方法是仅使用以下代码在QuickFix / n中启动连接之前检查套接字是否已打开

bool IsPortOpen(string host, int port, TimeSpan timeout)
{
    try
    {
        using(var client = new TcpClient())
        {
            var result = client.BeginConnect(host, port, null, null);
            var success = result.AsyncWaitHandle.WaitOne(timeout);
            if (!success)
            {
                return false;
            }

            client.EndConnect(result);
        }

    }
    catch
    {
        return false;
    }
    return true;
}

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

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