Exemplo n.º 1
0
        private void acceptCallback(IAsyncResult ar)
        {
            try
            {
                if (_closed || _closing)
                {
                    return;
                }
                Socket s       = ar.AsyncState as Socket;
                Socket wSocket = s.EndAccept(ar);
                //引发事件
                SocketAdapter adapter = new SocketAdapter(wSocket);
                adapter.Receive();
                OnClientAccepted(new ClientAcceptedEventArgs(adapter));

                s.BeginAccept(acceptCallback, s);
            }
            catch (SocketException se)
            {
                if (_closed || _closing)
                {
                    return;
                }
                OnErrorOccured(new ErrorEventArgs(se.Message, ErrorTypes.SocketAccept, se.ErrorCode, se));
            }
        }
Exemplo n.º 2
0
 private void buildAdapter(Socket soc)
 {
     _adapter = new SocketAdapter(soc);
     _adapter.SendCompleted    += Adapter_SendCompleted;
     _adapter.ReceiveCompleted += Adapter_ReceiveCompleted;
     _adapter.ErrorOccured     += Adapter_ErrorOccured;
     _adapter.Receive();
 }
Exemplo n.º 3
0
 private void destoryAdapter()
 {
     if (_adapter != null)
     {
         _adapter.SendCompleted    -= Adapter_SendCompleted;
         _adapter.ReceiveCompleted -= Adapter_ReceiveCompleted;
         _adapter.ErrorOccured     -= Adapter_ErrorOccured;
         _adapter.Close();
         _adapter = null;
     }
 }