コード例 #1
0
        /// <summary>
        /// Получает данные из сокета
        /// </summary>
        /// <param name="baseObj"></param>
        /// <returns></returns>
        public int Receive(object baseObj)
        {
            if (this.StateSock.wSocket == null)
            {
                return(0);
            }
            if (this.StateSock.wSocket.Available <= 0)
            {
                return(0);
            }

            int bytesRead = 0;

            try
            {
                if (this.StateSock.wSocket.IsBound)
                {
                    bytesRead = this.StateSock.wSocket.Receive(this.StateSock.buffer, 0, this.StateSock.buffer.Length, SocketFlags.Partial);
                    if (OnReceive != null)
                    {
                        OnReceive(baseObj, bytesRead, this.StateSock.buffer);
                    }
                }
            }
            catch (Exception e) { Qlog.Write(e.ToString()); };
            return(bytesRead);
        }
コード例 #2
0
ファイル: Qlog.cs プロジェクト: Socol111/QLuaConnector
 /// <summary>
 /// Функция отлова исключений и записи их в лог
 /// </summary>
 /// <param name="action">Обрабатываемое действие</param>
 static public void CatchException(Action action)
 {
     try
     {
         if (!action.Empty())
         {
             action();
         }
     } catch (Exception e)
     {
         Qlog.Write(e.ToString());
     }
 }
コード例 #3
0
 private static void SendCallback(IAsyncResult ar)
 {
     try
     {
         // Retrieve the socket from the state object.
         StateObject stateObj = (StateObject)ar.AsyncState;
         // Complete sending the data to the remote device.
         int bytesSent = stateObj.wSocket.EndSend(ar);
         //Console.WriteLine("Sent {0} bytes to client.", bytesSent);
     }
     catch (Exception e)
     {
         Qlog.Write(e.ToString());
     }
 }
コード例 #4
0
        /// <summary>
        /// Создает сокеты для подключения
        /// </summary>
        public void CreateSockets()
        {
            Qlog.CatchException(() =>
            {
                //if (MsgManager.ActiveStatus) return;
                MsgManager.Type    = 1;
                MsgManTraders.Type = 2;
                MsgManMarket.Type  = 3;

                MsgManager.OnNewSysMessage += new MManager.eventNewMessage(Event_OnNewSysMessage);

                this.OnAnswerServer += (command) => { };

                //Конект до сокета сервера
                if (MsgManager.ConnectSocket(Server.ServerAddr, Server.Port, true) == 0)
                {
                    //Активатор отложенных событий
                    MsgManager.AcivateAllEvent += () =>
                    {
                        if (MarketTools.ListAllDeferredEventBase.Count > 0)
                        {
                            foreach (var act in MarketTools.ListAllDeferredEventBase)
                            {
                                act.ExecEvent();
                            }
                        }
                    };
                    //Инициализация контроллекра сообщений
                    MsgManager.InitThreadsMessages();

                    this.isConnected = true;
                    MsgManager.Convertor.OnStartMarket += () =>
                    {
                        //MsgManTraders.PortionInTime = 1000;
                        if (MsgManTraders.ConnectSocket(Server.ServerAddr, Server.Port) == 0)
                        {
                            //Активатор отложенных событий
                            MsgManTraders.AcivateAllEvent += () =>
                            {
                                if (MarketTools.ListAllDeferredEventTrades.Count > 0)
                                {
                                    foreach (var act in MarketTools.ListAllDeferredEventTrades)
                                    {
                                        act.ExecEvent();
                                    }
                                }
                            };
                            MsgManTraders.InitThreadsMessages();
                        }
                        if (MsgManMarket.ConnectSocket(Server.ServerAddr, Server.Port) == 0)
                        {
                            MsgManTraders.AcivateAllEvent += () =>
                            {
                                if (MarketTools.ListAllDeferredEventMarkets.Count > 0)
                                {
                                    foreach (var act in MarketTools.ListAllDeferredEventMarkets)
                                    {
                                        act.ExecEvent();
                                    }
                                }
                            };
                            MsgManMarket.InitThreadsMessages();
                        }
                    };
                }
                else
                {
                    this.isConnected = false;
                }
            });
        }