Esempio n. 1
0
        public void ReadCallback(IAsyncResult ar)
        {
            stateObject state     = (stateObject)ar.AsyncState;
            Socket      handler   = state.workSocket;
            int         bytesRead = handler.EndReceive(ar);

            if (bytesRead > 0)
            {
                if (OnReceivingEvent != null)
                {
                    OnReceivingEvent(handler, state.buffer);
                }
            }
            handler.BeginReceive(state.buffer, 0, stateObject.bufferSize, 0, new AsyncCallback(ReadCallback), state);
        }
Esempio n. 2
0
        public void AcceptCallback(IAsyncResult ar)
        {
            Socket listener = (Socket)ar.AsyncState;
            Socket handler  = listener.EndAccept(ar);

            stateObject state = new stateObject();

            state.workSocket = handler;

            if (OnNewConnEvent != null)
            {
                OnNewConnEvent(handler);
            }

            handler.BeginReceive(state.buffer, 0, stateObject.bufferSize, 0, new AsyncCallback(ReadCallback), state);

            currentConnection.Set();
        }