Example #1
0
 public TWSCallback(Dictionary <string, string> work, ClosedCB ccb)
 {
     // No need to bother locking in the ctor. We are on the background
     // worker thread here, but we won't get methods fired on the pool
     // threads until this method exits.
     m_Key = work["key"];
     m_URL = work["url"];
     work.TryGetValue("auth_token", out m_AuthToken);
     m_ClosedCB = ccb;
     try {
         m_Client                  = new WebSocket(m_URL);
         m_RTMHandler              = new TiingoRealTimeMessageHandler(m_Client, MktDataTick, HeartBeat, SetSubID);
         m_Client.Opened          += new EventHandler(Opened);
         m_Client.Error           += new EventHandler <SuperSocket.ClientEngine.ErrorEventArgs>(Error);
         m_Client.Closed          += new EventHandler(Closed);
         m_Client.MessageReceived += new EventHandler <MessageReceivedEventArgs>(MessageReceived);
         m_Client.DataReceived    += new EventHandler <WebSocket4Net.DataReceivedEventArgs>(DataReceived);
         // Do we need to set up a proxy?
         if (work.TryGetValue("http_proxy_host", out m_ProxyHost))
         {
             IPHostEntry he   = Dns.GetHostEntry(m_ProxyHost);
             int         port = 80;
             if (work.TryGetValue("http_proxy_host", out m_ProxyPort))
             {
                 if (!Int32.TryParse(m_ProxyPort, out port))
                 {
                     port = 80;
                 }
             }
             var proxy = new HttpConnectProxy(new IPEndPoint(he.AddressList[0], port));
             // Do we need to supply authentication to the proxy?
             if (work.TryGetValue("http_proxy_user", out m_ProxyUser))
             {
                 work.TryGetValue("http_proxy_password", out m_ProxyPassword);
                 // encode user:password as base64 and supply as 'Proxy-Authorization: Basic dXNlbWU6dGVzdA=='
                 string upass          = String.Format("{0}:{1}", m_ProxyUser, m_ProxyPassword);
                 var    plainTextBytes = System.Text.Encoding.UTF8.GetBytes(upass);
                 string b64            = System.Convert.ToBase64String(plainTextBytes);
                 proxy.Authorization = String.Format("Basic {0}", b64);
             }
             m_Client.Proxy = proxy;
         }
         Logr.Log(String.Format("TWSCallback.ctor: key({0}) url({1}) auth_token({2}) http_proxy_host({3}) http_proxy_port({4}) http_proxy_user({5}) http_proxy_password({6})",
                                m_Key, m_URL, m_AuthToken, m_ProxyHost, m_ProxyPort, m_ProxyUser, m_ProxyPassword));
         m_Client.Open( );
     }
     catch (System.ArgumentException ae) {
         Logr.Log(String.Format("TWSCallback.ctor: {0}", ae.Message));
     }
     catch (System.FormatException fe) {
         Logr.Log(String.Format("TWSCallback.ctor: format error fmt({0}) auth({1}) err({2})", s_SubscribeMessageFormat, m_AuthToken, fe.Message));
     }
 }
Example #2
0
 public WSCallback( String wskey, String url, ClosedCB ccb )
 {
     // ctor will be invoked on the SSWebClient worker thread
     m_ClosedCB = ccb;
     m_Key = wskey;
     m_Client = new WebSocket( url );
     m_Client.Opened += new EventHandler( Opened );
     m_Client.Error += new EventHandler<SuperSocket.ClientEngine.ErrorEventArgs>( Error );
     m_Client.Closed += new EventHandler( Closed );
     m_Client.MessageReceived += new EventHandler<MessageReceivedEventArgs>( MessageReceived );
     m_Client.DataReceived += new EventHandler<WebSocket4Net.DataReceivedEventArgs>( DataReceived );
     m_Client.Open( );
 }
Example #3
0
 public WSCallback(String wskey, String url, ClosedCB ccb)
 {
     // ctor will be invoked on the SSWebClient worker thread
     m_ClosedCB                = ccb;
     m_Key                     = wskey;
     m_Client                  = new WebSocket(url);
     m_Client.Opened          += new EventHandler(Opened);
     m_Client.Error           += new EventHandler <SuperSocket.ClientEngine.ErrorEventArgs>(Error);
     m_Client.Closed          += new EventHandler(Closed);
     m_Client.MessageReceived += new EventHandler <MessageReceivedEventArgs>(MessageReceived);
     m_Client.DataReceived    += new EventHandler <WebSocket4Net.DataReceivedEventArgs>(DataReceived);
     m_Client.Open( );
 }
Example #4
0
        public WSCallback(Dictionary <string, string> work, ClosedCB ccb)
        {
            // ctor will be invoked on the SSWebClient worker thread
            m_ClosedCB = ccb;
            m_Key      = work["key"];
            string url = work["url"];

            try {
                m_Client                  = new WebSocket(url);
                m_Client.Opened          += new EventHandler(Opened);
                m_Client.Error           += new EventHandler <SuperSocket.ClientEngine.ErrorEventArgs>(Error);
                m_Client.Closed          += new EventHandler(Closed);
                m_Client.MessageReceived += new EventHandler <MessageReceivedEventArgs>(MessageReceived);
                m_Client.DataReceived    += new EventHandler <WebSocket4Net.DataReceivedEventArgs>(DataReceived);
                m_Client.Open( );
            }
            catch (System.ArgumentException ae) {
                Logr.Log(String.Format("WSCallback.ctor: {0}", ae.Message));
            }
        }