示例#1
0
        /// <summary>
        /// Server recive mode
        /// </summary>
        /// <param name="_socket"></param>
        private void ReciveMode(Socket _socket)
        {
            int l;

            while (true)
            {
                try
                {
                    Socket tmpSocket = _socket.Accept();
                    byte[] buffer    = new byte[1024];
                    l = tmpSocket.Receive(buffer);

                    index = Encoding.Unicode.GetString(buffer, 0, l); //получение индекса от клиента

                    //Вывод в консоль данные о подключенном клиенте
                    IPEndPoint remoteIpEndPoint = tmpSocket.RemoteEndPoint as IPEndPoint;
                    Console.WriteLine(DateTime.Now.ToString());
                    if (remoteIpEndPoint != null)
                    {
                        Console.WriteLine("Connection from " + remoteIpEndPoint.Address + ":" + remoteIpEndPoint.Port);
                        Console.WriteLine("Resive data >>> " + index);
                    }
                    else
                    {
                        Console.WriteLine(tmpSocket.RemoteEndPoint.ToString() + " >>> " + index);
                    }

                    DelegateConnect dc = new DelegateConnect(SendMode);
                    dc.BeginInvoke(tmpSocket, null, null);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
示例#2
0
 public IAsyncResult BeginConnectTLS(string host, int port, AsyncCallback callback)
 {
     this._delegateConnect = this.ConnectTLS;
     return this._delegateConnect.BeginInvoke(host, port, callback, this._delegateConnect);
 }
示例#3
0
 /// <summary>
 /// Begins the connect.
 /// </summary>
 /// <param name="host">The host.</param>
 /// <param name="port">The port.</param>
 /// <param name="callback">The callback.</param>
 /// <returns></returns>
 public override IAsyncResult BeginConnectPlain(string host, int port, AsyncCallback callback)
 {
     this._delegateConnect = this.ConnectPlain;
     return this._delegateConnect.BeginInvoke(host, port, callback, this._delegateConnect);
 }
示例#4
0
 /// <summary>
 /// Begins the connect.
 /// </summary>
 /// <param name="host">The host.</param>
 /// <param name="callback">The callback.</param>
 /// <returns></returns>
 public IAsyncResult BeginConnect(string host, AsyncCallback callback)
 {
     this._delegateConnect = this.ConnectPlain;
     return this._delegateConnect.BeginInvoke(host, 143, callback, this._delegateConnect);
 }
示例#5
0
        /// <summary>
        /// 加载程序集
        /// </summary>
        private void LoadAssembly()
        {
            try
            {
                string path = Path.GetFullPath(string.Format("{0}\\{1}", LibraryWrapper.ProcessorArchitecture,
                                                             DllName));
                _wrapper = new LibraryWrapper(path, "thostmduserapi.dll");

                #region 读取方法入口列表

                string resourceName = string.Format("CTPMarketApi.Entry{0}.txt", LibraryWrapper.IsAmd64 ? "64" : "32");
                var    assembly     = System.Reflection.Assembly.GetExecutingAssembly();
                Stream stream       = assembly.GetManifestResourceStream(resourceName);
                if (stream != null)
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string text       = reader.ReadToEnd();
                        string entryStart = "ordinal hint";
                        int    start      = text.IndexOf(entryStart);
                        if (start > -1)
                        {
                            string[] arr = text.Substring(start).Split('\n');
                            if (arr.Length > 1)
                            {
                                for (int i = 1; i < arr.Length; i++)
                                {
                                    string[] list = arr[i].Split(new char[] { ' ', '\t' },
                                                                 StringSplitOptions.RemoveEmptyEntries);
                                    if (list.Length > 4)
                                    {
                                        _entryList.Add(list[3]);
                                    }
                                }
                            }
                        }
                    }
                    stream.Close();
                }
                if (_entryList.Count == 0)
                {
                    throw new Exception(string.Format("Cannot find entry point form resource {0}", resourceName));
                }

                #endregion

                #region 获取非托管方法

                createSpi               = GetDelegate <DelegateCreateSpi>("CreateSpi");
                getApiVersion           = GetDelegate <DelegateGetString>("GetApiVersion");
                getTradingDay           = GetDelegate <DelegatetTradingDay>("GetTradingDay");
                connect                 = GetDelegate <DelegateConnect>("Connect");
                disconnect              = GetDelegate <DelegateDisconnect>("DisConnect");
                userLogin               = GetDelegate <DelegateUserLogin>("ReqUserLogin");
                userLogout              = GetDelegate <DelegateUserLogout>("ReqUserLogout");
                subscribeMarketData     = GetDelegate <DelegateSubscribeMarketData>("SubMarketData");
                unsubscribeMarketData   = GetDelegate <DelegateUnsubscribeMarketData>("UnSubscribeMarketData");
                regOnRspError           = GetDelegate <DelegateRegOnRspError>("RegOnRspError");
                regOnHeartBeatWarning   = GetDelegate <DelegateRegOnHeartBeatWarning>("RegOnHeartBeatWarning");
                regOnFrontConnected     = GetDelegate <DelegateRegOnFrontConnected>("RegOnFrontConnected");
                regOnFrontDisconnected  = GetDelegate <DelegateRegOnFrontDisconnected>("RegOnFrontDisconnected");
                regOnRspUserLogin       = GetDelegate <DelegateRegOnRspUserLogin>("RegOnRspUserLogin");
                regOnRspUserLogout      = GetDelegate <DelegateRegOnRspUserLogout>("RegOnRspUserLogout");
                regOnRspSubMarketData   = GetDelegate <DelegateRegOnRspSubMarketData>("RegOnRspSubMarketData");
                regOnRspUnSubMarketData = GetDelegate <DelegateRegOnRspUnSubMarketData>("RegOnRspUnSubMarketData");
                regOnRtnDepthMarketData = GetDelegate <DelegateRegOnRtnDepthMarketData>("RegOnRtnDepthMarketData");

                #endregion

                _spi = createSpi();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }