Example #1
0
        /// <summary>
        /// 初始化(必要)
        /// </summary>
        /// <param name="maxConn"></param>
        public virtual void Init(string id)
        {
            transfer      = new Transfer(maxConnect);
            registerWaite = new AutoResetEvent(false);
            this.Id       = id;
            YDataPacketManager.RegisterDataPacket(typeof(SplitDataPacket));
            YDataPacketManager.RegisterDataPacket(typeof(SocketRegisterPacket));
            YDataPacketManager.RegisterDataPacket(typeof(MessagePack));
            socketPool = new SocketAsyncEventArgsPool(maxConnect);
            SocketAsyncEventArgs readWriteEventArg;

            bufferManager = new BufferManager(maxConnect * bufferLenthg * 2, bufferLenthg);
            bufferManager.InitBuffer();
            for (int i = 0; i < maxConnect; i++)
            {
                readWriteEventArg = new SocketAsyncEventArgs();
                bufferManager.SetBuffer(readWriteEventArg);
                socketPool.Push(readWriteEventArg);
            }
            netTree.CreateRoot(id);
            AbsInit();
            isInit = true;
        }