Пример #1
0
        private static void DoAcceptTcpClient(IAsyncResult ar)
        {
            IoAcceptState acceptState = (IoAcceptState)ar.AsyncState;

            try
            {
                TcpClient client = acceptState.EndAcceptTcpClient(ar);
                if (client == null)
                {
                    acceptState.mHeader.SessionClosed(acceptState.mHeader.GetPID());
                }
                else
                {
                    IoClientState sockState = new IoClientState(acceptState.mHeader, acceptState.mBufferSize, client);
                    acceptState.mHeader.ConnectOpened(sockState); //接收到连接消息
                    sockState.SetStream(client.GetStream());
                    sockState.BeginRead();
                    acceptState.BeginAcceptTcpClient();
                }
            }
            catch (Exception ex)
            {
                acceptState.mHeader.SessionClosed(acceptState.mHeader.GetPID());
                acceptState.mHeader.SessionException(acceptState, ex);
            }
        }
Пример #2
0
 public void CloseConnect()
 {
     lock (mIoStates)
     {
         foreach (IoState item in mIoStates.Values)
         {
             IoClientState clientState = item as IoClientState;
             clientState.Close();
         }
         mIoStates.Clear();
     }
 }