示例#1
0
 private void acceptCallback(IAsyncResult ar)
 {
     try
     {
         timer.Enabled = false;
         socket        = listenSocket.EndAccept(ar);
         DccStateObject dso = new DccStateObject();
         socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso);
         listenSocket.Close();
         if (socket.Connected)
         {
             Connected();
         }
         else
         {
             if (EtablishFailed != null)
             {
                 EtablishFailed(this, new EventArgs());
             }
             container.Remove(this);
         }
     }
     catch
     {
         if (EtablishFailed != null)
         {
             EtablishFailed(this, new EventArgs());
         }
         container.Remove(this);
     }
 }
示例#2
0
        private void receiveCallback(IAsyncResult ar)
        {
            DccStateObject dso = (DccStateObject)ar.AsyncState;

            try
            {
                int intRead = socket.EndReceive(ar);
                if (intRead > 0)
                {
                    OnData(dso.Buffer, intRead);
                    socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso);
                }
                else
                {
                    CloseSocket();
                    Disconnected();
                    container.Remove(this);
                }
            }
            catch
            {
                CloseSocket();
                Disconnected();
                container.Remove(this);
            }
        }
示例#3
0
        private void connectCallback(IAsyncResult ar)
        {
            try
            {
                socket.EndConnect(ar);
            }
            catch
            {
                if (EtablishFailed != null)
                {
                    EtablishFailed(this, new EventArgs());
                }
                return;
            }

            if (socket.Connected)
            {
                DccStateObject dso = new DccStateObject();
                socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso);
                Connected();
            }
            else
            {
                CloseSocket();
                if (EtablishFailed != null)
                {
                    EtablishFailed(this, new EventArgs());
                }
                container.Remove(this);
            }
        }
示例#4
0
        private void connectCallback(IAsyncResult ar)
        {
            try
            {
                socket.EndConnect(ar);
            }
            catch
            {
                if (EtablishFailed != null)
                    EtablishFailed(this, new EventArgs());
                return;
            }

            if (socket.Connected)
            {
                DccStateObject dso = new DccStateObject();
                socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso);
                Connected();
            }
            else
            {
                CloseSocket();
                if (EtablishFailed!=null)
                    EtablishFailed(this, new EventArgs());
                container.Remove(this);
            }
        }
示例#5
0
 private void acceptCallback(IAsyncResult ar)
 {
     try
     {
         timer.Enabled = false;
         socket = listenSocket.EndAccept(ar);
         DccStateObject dso = new DccStateObject();
         socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso);
         listenSocket.Close();
         if (socket.Connected)
             Connected();
         else
         {
             if (EtablishFailed!=null)
                 EtablishFailed(this, new EventArgs());
             container.Remove(this);
         }
     }
     catch
     {
         if (EtablishFailed!=null)
             EtablishFailed(this, new EventArgs());
         container.Remove(this);
     }
 }