Beispiel #1
0
        private void ReceiveCb(IAsyncResult ar)
        {
            ConnToClient CTC = (ConnToClient)ar.AsyncState;

            try
            {
                if (CTC.IsUse == false)
                {
                    return;
                }
                int count = CTC.socket.EndReceive(ar);
                if (count <= 0)
                {
                    CTC.Close();
                    return;
                }
                CTC.BufferCount += count;
                PrcessByte(CTC);
                CTC.socket.BeginReceive(CTC.ReadBuffer, CTC.BufferCount, CTC.RetCount(), SocketFlags.None, ReceiveCb, CTC);
            }
            catch (Exception e)
            {
                CTC.Close();
                Console.WriteLine(e.Message);
            }
        }
Beispiel #2
0
        private void AcceptCb(IAsyncResult ar)
        {
            Socket RetCSocket = socket.EndAccept(ar);
            int    Index      = NewIndex();

            SCTCS[Index] = new ConnToClient();
            ConnToClient CTC = SCTCS[Index];

            ClientOnlineNumber++;
            CTC.Init(RetCSocket);
            CTC.socket.BeginReceive(CTC.ReadBuffer, CTC.BufferCount, CTC.RetCount(), SocketFlags.None, ReceiveCb, CTC);
            socket.BeginAccept(AcceptCb, null);
        }