示例#1
0
        /// <summary>
        /// Fills the pools.
        /// </summary>
        private static void FillPools()
        {
            NetworkTcp.ReadPool  = new NetworkPool();
            NetworkTcp.WritePool = new NetworkPool();

            for (int i = 0; i < Config.MaxPlayers; i++)
            {
                var AsyncEvent = new SocketAsyncEventArgs();

                AsyncEvent.SetBuffer(new byte[Config.BufferSize], 0, Config.BufferSize);
                AsyncEvent.DisconnectReuseSocket = true;
                AsyncEvent.Completed            += NetworkTcp.OnReceiveCompleted;

                NetworkTcp.ReadPool.Enqueue(AsyncEvent);
            }

            for (int i = 0; i < Config.MaxPlayers; i++)
            {
                var AsyncEvent = new SocketAsyncEventArgs();
                AsyncEvent.DisconnectReuseSocket = true;
                AsyncEvent.Completed            += NetworkTcp.OnSendCompleted;

                NetworkTcp.WritePool.Enqueue(AsyncEvent);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkGateway"/> class.
        /// </summary>
        public static void Initialize()
        {
            if (NetworkTcp.Initialized)
            {
                return;
            }

            NetworkTcp.ReadPool  = new NetworkPool();
            NetworkTcp.WritePool = new NetworkPool();

            foreach (var AsyncEvent in NetworkTcp.ReadPool)
            {
                AsyncEvent.Completed += NetworkTcp.OnReceiveCompleted;
            }

            foreach (var AsyncEvent in NetworkTcp.WritePool)
            {
                AsyncEvent.Completed += NetworkTcp.OnSendCompleted;
            }

            NetworkTcp.Initialized = true;
        }