Client Failed to initiate an advise loop

Dec 17, 2013 at 4:35 PM
Edited Dec 17, 2013 at 4:36 PM
Hi guys,
This is Vipin. I have been working on this DDE client thing for extracting data from eSignal but at times my client application crashes with this exception "Client failed to initiate an advise loop". What boggles my mind is couple of weeks ago this same code was running fine. But one day when I restarted my system and tried to execute the program, it gave me the "failed to initiate advise loop exception" and since then I have not been able to run my program.
Error seems to be coming from "client.StartAdvise(item, 1, true,60000)" marked in bold letters. I just feel there is some thing I am missing out.

Please help me out in this as I am really facing some stiff deadlines.

Thanks and Regards,
Vipin Anand
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NDde.Client;
using daslibrary;

namespace ESignalDASConnectorDDE
{
    class ESignalDASConnectorDDEClient
    {
            public static Dictionary<String, ESignalDASConnectorDDEClient> clientMap = new  Dictionary<string, ESignalDASConnectorDDEClient>();

        public ESignalDASConnectorDDEClient(string service, string topic, string item)
        {
            client = new DdeClient(service, topic);
            this.symbol = item.Substring(item.IndexOf("_") + 1);

            if (ESignalDASConnectorDDEClient.sOS == null || !ESignalDASConnectorDDEClient.sOS.IsConnected())
            {
                this.connectSocketOrderServer();
            }
            this.orderEvent = new EventHandler<OrderActiveArgs>(OrderActiveHandler);
            this.lv1Event = new EventHandler<Lv1Args>(Lv1Handler);
            this.tradeEvent = new EventHandler<TradeArgs>(this.TradeActiveHandler);
            sOS.eventPool.Subscribe("Trade", this.tradeEvent);
            sOS.eventPool.Subscribe("Order", this.orderEvent);
            sOS.eventPool.Subscribe("Lv1", this.lv1Event);
            client.Disconnected += OnDisconnected;
            client.Connect();
            client.Advise += OnAdvise;
            runClient(service, topic, item);
        }

      
        private void runClient(string service, string topic, string item)
        {
            if (client != null)
            {
                __client.StartAdvise(item, 1, true, 60000);__
            }

        }

        private static void OnExecuteComplete(IAsyncResult ar)
        {
            try
            {
                DdeClient client = (DdeClient)ar.AsyncState;
                client.EndExecute(ar);
                Console.WriteLine("OnExecuteComplete");
            }
            catch (Exception e)
            {
                Console.WriteLine("OnExecuteComplete: " + e.Message);
            }
        }

        private static void OnPokeComplete(IAsyncResult ar)
        {
            try
            {
                DdeClient client = (DdeClient)ar.AsyncState;
                client.EndPoke(ar);
                Console.WriteLine("OnPokeComplete");
            }
            catch (Exception e)
            {
                Console.WriteLine("OnPokeComplete: " + e.Message);
            }
        }

        private static void OnRequestComplete(IAsyncResult ar)
        {
            try
            {
                DdeClient client = (DdeClient)ar.AsyncState;
                byte[] data = client.EndRequest(ar);
                Console.WriteLine("OnRequestComplete: " + Encoding.ASCII.GetString(data));
            }
            catch (Exception e)
            {
                Console.WriteLine("OnRequestComplete: " + e.Message);
            }
        }

        private static void OnStartAdviseComplete(IAsyncResult ar)
        {
            try
            {
                DdeClient client = (DdeClient)ar.AsyncState;
                client.EndStartAdvise(ar);
                Console.WriteLine("OnStartAdviseComplete");
            }
            catch (Exception e)
            {
                Console.WriteLine("OnStartAdviseComplete: " + e.Message);
            }
        }

        private static void OnStopAdviseComplete(IAsyncResult ar)
        {
            try
            {
                DdeClient client = (DdeClient)ar.AsyncState;
                client.EndStopAdvise(ar);
                Console.WriteLine("OnStopAdviseComplete");
            }
            catch (Exception e)
            {
                Console.WriteLine("OnStopAdviseComplete: " + e.Message);
            }
        }

        private static void OnAdvise(object sender, DdeAdviseEventArgs args)
        {
            Console.WriteLine("OnAdvise: " + args.Text);
            string[] splitString = args.Text.Split(new char[] { ',' });
            bool isMarketOrder = splitString[0].Equals("MARKET") ? true : false;
            double tradePrice = Double.Parse(splitString[1]);
            int lotSize = Int32.Parse(splitString[2]);
            bool isBuyOrder = (splitString[3].Equals("LONG") || splitString[3].Equals("Cover")) ? true : false;
            ESignalDASConnectorDDEClient.quoteServer.WLSTAddWatch(splitString[4].Trim());
            while (!ESignalDASConnectorDDEClient.clientMap[splitString[4].Trim()].isQuoteSet) ;
            ESignalDASConnectorDDEClient.quoteServer.WLSTRemoveWatch(splitString[4].Trim());
            itemOrder iOrder = ESignalDASConnectorDDEClient.clientMap[splitString[4].Trim()].createOrder(splitString[4], lotSize, tradePrice, isBuyOrder, isMarketOrder);
            String errMsg = "";
            long mOrig = -1;
            itemOrder.LSendOrder(iOrder, ref errMsg, true, ESignalDASConnectorDDEClient.sOS, ref mOrig);
        }

        private static void OnDisconnected(object sender, DdeDisconnectedEventArgs args)
        {
            Console.WriteLine(
                "OnDisconnected: " +
                "IsServerInitiated=" + args.IsServerInitiated.ToString() + " " +
                "IsDisposed=" + args.IsDisposed.ToString());

        }
   static void Main(string[] args)
        {
            ESignalDASConnectorDDEClient[] client = new ESignalDASConnectorDDEClient[6];
            String[] builder = { "TNA","FAS" };/*,"GLD","SPY"};*/
            int i = 0;
            while (true)
            {
                if (client[i] == null && i < builder.Length)
                {
                    client[i] = new ESignalDASConnectorDDEClient("eSignal", "EFS", "DASConnector_" + builder[i]); //DASConnector_
                    clientMap.Add(builder[i], client[i]);
                    i++;
                }
            
            }
        }
    }
}
Feb 14, 2014 at 5:41 PM
Edited Feb 14, 2014 at 5:42 PM
We are also experiencing something similar.The client just stops recieving the message when the server runs Advise after a perior of time. Does anyone have a clue?

--Sean
Jul 22, 2014 at 5:43 PM
Edited Jul 22, 2014 at 5:44 PM
seanwhyte wrote:
We are also experiencing something similar.The client just stops recieving the message when the server runs Advise after a perior of time. Does anyone have a clue?

--Sean
Sean, did you find out why the client stops recieving the message after a period of time? I got the same problem and I'm really looking for its solutions. Please reply if you already found one, really appreciate that. Thanks.