コード例 #1
0
        private static void OnAcceptTcpClient(IAsyncResult ar)
        {
            soteSFIS2Fxcn asyncState = (soteSFIS2Fxcn)ar.AsyncState;
            bool          flag1      = false;
            bool          flag2      = false;
            Exception     e          = (Exception)null;

            lock (asyncState)
            {
                try
                {
                    asyncState.m_Client         = asyncState.m_Listener.EndAcceptTcpClient(ar);
                    asyncState.m_RemoteEndPoint = asyncState.m_Client.Client.RemoteEndPoint;
                    asyncState.m_ClientStream   = asyncState.m_Client.GetStream();
                    asyncState.SendMessageUnlocked(asyncState.m_OperatorId, false);
                    asyncState.m_ClientStream.BeginRead(asyncState.m_DataBuffer, 0, asyncState.m_DataBuffer.Length, new AsyncCallback(soteSFIS2Fxcn.OnStreamRead), (object)asyncState);
                    asyncState.m_Timer.Change(0, 3000);
                    asyncState.m_Listener.Stop();
                    asyncState.m_OpenState = soteSFIS2Fxcn.OpenStates.Connected;
                    flag1 = true;
                }
                catch (Exception ex)
                {
                    flag2 = true;
                    e     = ex;
                    if (asyncState.m_ClientStream != null)
                    {
                        asyncState.m_ClientStream.Close();
                        asyncState.m_ClientStream = (NetworkStream)null;
                    }
                    if (asyncState.m_Client != null)
                    {
                        asyncState.m_Client.Close();
                        asyncState.m_Client = (TcpClient)null;
                    }
                    asyncState.m_RemoteEndPoint = (EndPoint)null;
                    asyncState.m_Timer.Change(-1, 3000);
                }
            }
            if (flag2)
            {
                asyncState.OnError((IsoteSFIS2)asyncState, e);
            }
            else
            {
                if (!flag1)
                {
                    return;
                }
                asyncState.OnConnected((IsoteSFIS2)asyncState);
            }
        }
コード例 #2
0
        private static void OnStreamRead(IAsyncResult ar)
        {
            soteSFIS2Fxcn    asyncState    = (soteSFIS2Fxcn)ar.AsyncState;
            bool             flag1         = false;
            List <Exception> exceptionList = (List <Exception>)null;
            bool             flag2         = false;

            lock (asyncState)
            {
                if (asyncState.m_ClientStream == null)
                {
                    return;
                }
                try
                {
                    int count1 = asyncState.m_ClientStream.EndRead(ar);
                    if (count1 > 0)
                    {
                        string rawMessage = asyncState.m_Encoding.GetString(asyncState.m_DataBuffer, 0, count1);
                        while (asyncState.m_ClientStream.DataAvailable)
                        {
                            int count2 = asyncState.m_ClientStream.Read(asyncState.m_DataBuffer, 0, asyncState.m_DataBuffer.Length);
                            if (count2 > 0)
                            {
                                rawMessage += asyncState.m_Encoding.GetString(asyncState.m_DataBuffer, 0, count2);
                            }
                        }
                        asyncState.Log(rawMessage, LogDetailLevels.RawMessage);
                        string str1      = rawMessage;
                        char[] separator = new char[2] {
                            '\r', '\n'
                        };
                        foreach (string str2 in str1.Split(separator, StringSplitOptions.RemoveEmptyEntries))
                        {
                            asyncState.ProcessMessageUnlocked(str2.Trim());
                        }
                        asyncState.m_ClientStream.BeginRead(asyncState.m_DataBuffer, 0, asyncState.m_DataBuffer.Length, new AsyncCallback(soteSFIS2Fxcn.OnStreamRead), (object)asyncState);
                    }
                    else
                    {
                        flag1 = true;
                        asyncState.HandleSocketFailure((Exception)null, ref exceptionList);
                    }
                }
                catch (Exception ex)
                {
                    flag1 = true;
                    flag2 = true;
                    asyncState.HandleSocketFailure(ex, ref exceptionList);
                }
            }
            if (flag1)
            {
                asyncState.OnDisconnected((IsoteSFIS2)asyncState);
            }
            if (!flag2)
            {
                return;
            }
            foreach (Exception e in exceptionList)
            {
                asyncState.OnError((IsoteSFIS2)asyncState, e);
            }
        }