Exemplo n.º 1
0
        private void ReceiveCb(IAsyncResult ar)
        {
            ServerConn SC = (ServerConn)ar.AsyncState;

            try
            {
                if (SC.IsUse == false)
                {
                    return;
                }
                int count = SC.socket.EndReceive(ar);
                if (count <= 0)
                {
                    SC.Close();
                    OnlineServer.Remove(SC);
                    return;
                }
                SC.bufferCount += count;
                PrcessByte(SC);
                SC.socket.BeginReceive(SC.ReadBuffer, SC.bufferCount, SC.BuffeMain(), SocketFlags.None, ReceiveCb, SC);
            }
            catch (Exception e)
            {
                SC.Close();
                OnlineServer.Remove(SC);
            }
        }
Exemplo n.º 2
0
        private void AcceptCb(IAsyncResult ar)
        {
            Socket RetSocket = socket.EndAccept(ar);
            int    index     = NewIndex();

            if (index < 0)
            {
                RetSocket.Close();
                return;
            }
            ServerConn SC = SCS[index];

            OnlineServer.Add(SC);
            SC.Init(RetSocket);
            SC.socket.BeginReceive(SC.ReadBuffer, SC.bufferCount, SC.BuffeMain(), SocketFlags.None, ReceiveCb, SC);
            socket.BeginAccept(AcceptCb, null);
        }