Exemplo n.º 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());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkManagerAsync"/> class.
        /// </summary>
        /// <param name="connection"><see cref="Socket"/> to wrap.</param>
        /// <exception cref="ArgumentNullException"/>
        public NetworkManagerAsync(Socket connection)
        {
            if (connection == null)
                throw new ArgumentNullException("connection");

            Connection = connection;
            Settings = new NetworkManagerAsyncSettings(); // default settings
            CoCCrypto = new CoCCrypto();
            ReceiveEventPool = new SocketAsyncEventArgsPool(25);
            SendEventPool = new SocketAsyncEventArgsPool(25);
            SetAsyncOperationPools();

            StartReceive(ReceiveEventPool.Pop());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkManagerAsync"/> class.
        /// </summary>
        /// <param name="connection"><see cref="Socket"/> to wrap.</param>
        /// <exception cref="ArgumentNullException"/>
        public NetworkManagerAsync(Socket connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            Connection       = connection;
            Settings         = new NetworkManagerAsyncSettings(); // default settings
            CoCCrypto        = new CoCCrypto();
            ReceiveEventPool = new SocketAsyncEventArgsPool(25);
            SendEventPool    = new SocketAsyncEventArgsPool(25);
            SetAsyncOperationPools();

            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;
            CoCCrypto = new CoCCrypto();
            ReceiveEventPool = new SocketAsyncEventArgsPool(25);
            SendEventPool = new SocketAsyncEventArgsPool(25);
            StartReceive(ReceiveEventPool.Pop());
        }