Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkManagerAsync"/> class.
        /// </summary>
        /// <param name="connection"><see cref="Socket"/> to wrap.</param>
        /// <param name="networkHandler"><see cref="PacketReceivedHandler"/> that will handle incoming packet.</param>
        /// <param name="packetReceivedFailedHandler"><see cref="PacketReceivedFailedHandler"/> that will handle incoming packet that failed to read.</param>
        /// <exception cref="System.ArgumentNullException"/>
        public NetworkManagerAsync(Socket connection,
                                   PacketReceivedHandler packetReceivedHandler,
                                   PacketReceivedFailedHandler packetReceivedFailedHandler)
        {
            if (PacketDictionary == null)  // could a use a static constructor?
            {
                InitializePacketDictionary();
            }
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (packetReceivedHandler == null)
            {
                throw new ArgumentNullException("packetReceivedHandler");
            }


            Connection           = connection;
            PacketReceived       = packetReceivedHandler;
            PacketReceivedFailed = packetReceivedFailedHandler;
            CoCCrypto            = new CoCCrypto();
            ReceiveEventPool     = new SocketAsyncEventArgsPool(25);
            SendEventPool        = new SocketAsyncEventArgsPool(25);
            StartReceive(ReceiveEventPool.Pop());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkManagerAsync"/> class.
        /// </summary>
        /// <param name="connection"><see cref="Socket"/> to wrap.</param>
        /// <param name="networkHandler"><see cref="PacketReceivedHandler"/> that will handle incoming packet.</param>
        /// <param name="packetReceivedFailedHandler"><see cref="PacketReceivedFailedHandler"/> that will handle incoming packet that failed to read.</param>
        /// <exception cref="System.ArgumentNullException"/>
        public NetworkManagerAsync(Socket connection,
                                   PacketReceivedHandler packetReceivedHandler,
                                   PacketReceivedFailedHandler packetReceivedFailedHandler)
        {
            if (PacketDictionary == null)  // could a use a static constructor?
            {
                InitializePacketDictionary();
            }
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (packetReceivedHandler == null)
            {
                throw new ArgumentNullException("packetReceivedHandler");
            }


            Connection           = connection;
            PacketReceived       = packetReceivedHandler;
            PacketReceivedFailed = packetReceivedFailedHandler;
            Seed             = MathHelper.Random.Next(); // must make this moar flexible
            CoCCrypto        = new CoCCrypto();
            ReceiveEventPool = new SocketAsyncEventArgsPool(25);
            SendEventPool    = new SocketAsyncEventArgsPool(25);
            StartReceive();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkManagerAsync"/> class.
        /// </summary>
        /// <param name="connection"><see cref="Socket"/> to wrap.</param>
        /// <param name="networkHandler"><see cref="PacketReceivedHandler"/> that will handle incoming packet.</param>
        /// <param name="packetReceivedFailedHandler"><see cref="PacketReceivedFailedHandler"/> that will handle incoming packet that failed to read.</param>
        /// <exception cref="System.ArgumentNullException"/>
        public NetworkManagerAsync(Socket connection,
                              PacketReceivedHandler packetReceivedHandler,
                              PacketReceivedFailedHandler packetReceivedFailedHandler)
        {
            if (PacketDictionary == null)  // could a use a static constructor?
                InitializePacketDictionary();
            if (connection == null)
                throw new ArgumentNullException("connection");
            if (packetReceivedHandler == null)
                throw new ArgumentNullException("packetReceivedHandler");

            Connection = connection;
            PacketReceived = packetReceivedHandler;
            PacketReceivedFailed = packetReceivedFailedHandler;
            CoCCrypto = new CoCCrypto();
            ReceiveEventPool = new SocketAsyncEventArgsPool(25);
            SendEventPool = new SocketAsyncEventArgsPool(25);
            StartReceive(ReceiveEventPool.Pop());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkManagerAsync"/> class.
        /// </summary>
        /// <param name="connection"><see cref="Socket"/> to wrap.</param>
        /// <param name="networkHandler"><see cref="PacketReceivedHandler"/> that will handle incoming packet.</param>
        /// <param name="packetReceivedFailedHandler"><see cref="PacketReceivedFailedHandler"/> that will handle incoming packet that failed to read.</param>
        /// <exception cref="System.ArgumentNullException"/>
        public NetworkManagerAsync(Socket connection,
                              PacketReceivedHandler packetReceivedHandler,
                              PacketReceivedFailedHandler packetReceivedFailedHandler)
        {
            if (PacketDictionary == null)  // could a use a static constructor?
                InitializePacketDictionary();
            if (connection == null)
                throw new ArgumentNullException("connection");
            if (packetReceivedHandler == null)
                throw new ArgumentNullException("packetReceivedHandler");

            Connection = connection;
            PacketReceived = packetReceivedHandler;
            PacketReceivedFailed = packetReceivedFailedHandler;
            Seed = MathHelper.Random.Next(); // must make this moar flexible
            CoCCrypto = new CoCCrypto();
            ReceiveEventPool = new SocketAsyncEventArgsPool(25);
            SendEventPool = new SocketAsyncEventArgsPool(25);
            StartReceive();
        }