public ClientPacketProcessor(ClientBuilderOptions options,
                                     IPacketSerialiser packetSerialiser,
                                     ILogger logger,
                                     IPacketHandlers packetHandlers)
        {
            this.options          = options;
            this.packetSerialiser = packetSerialiser;
            this.logger           = logger;
            this.packetHandlers   = packetHandlers;

            this.tcpSenderObjectPool = new ObjectPool <ISender>(options.ObjectPoolSize);

            for (var i = 0; i < this.tcpSenderObjectPool.Capacity; i++)
            {
                this.tcpSenderObjectPool.Push(new TcpSender(packetSerialiser));
            }

            this.udpSenderObjectPool = new ObjectPool <ISender>(options.ObjectPoolSize);

            for (var i = 0; i < this.udpSenderObjectPool.Capacity; i++)
            {
                this.udpSenderObjectPool.Push(new UdpSender(packetSerialiser));
            }

            this.bytePool = new ObjectPool <byte[]>(options.ObjectPoolSize);

            for (int i = 0; i < this.bytePool.Capacity; i++)
            {
                this.bytePool.Push(new byte[options.PacketSizeBuffer]);
            }
        }
示例#2
0
 public ClientBuilder()
 {
     this.options           = new ClientBuilderOptions();
     this.serviceCollection = new ServiceCollection();
     this.modules           = new List <IPacketHandlerModule>();
     this.module            = new PacketHandlerModule();
     this.modules.Add(this.module);
 }
示例#3
0
 public Client(ClientBuilderOptions options,
               IPacketSerialiser packetSerialiser,
               IClientPacketProcessor packetProcessor,
               ILogger logger)
 {
     this.options          = options;
     this.packetSerialiser = packetSerialiser;
     this.packetProcessor  = packetProcessor;
     this.logger           = logger;
 }
示例#4
0
 public Client(ClientBuilderOptions options,
               IPacketSerialiser packetSerialiser,
               IClientPacketProcessor packetProcessor,
               ILogger <Client> logger)
 {
     this.options          = options;
     this.packetSerialiser = packetSerialiser;
     this.packetProcessor  = packetProcessor;
     this.logger           = logger;
     this.pingPacketBuffer = Encoding.ASCII.GetBytes("aaaaaaaaaaaaaaaaaaaaaaaa");
     this.pingOptions      = new PingOptions(64, true);
 }
示例#5
0
        public ClientPacketProcessor(ClientBuilderOptions options,
                                     IPacketSerialiser packetSerialiser,
                                     ILogger <ClientPacketProcessor> logger,
                                     IPacketHandlers packetHandlers)
        {
            this.options          = options;
            this.packetSerialiser = packetSerialiser;
            this.logger           = logger;
            this.packetHandlers   = packetHandlers;

            tcpSenderObjectPool = new ObjectPool <ISender>(options.ObjectPoolSize);

            for (var i = 0; i < tcpSenderObjectPool.Capacity; i++)
            {
                tcpSenderObjectPool.Push(new TcpSender(packetSerialiser));
            }

            udpSenderObjectPool = new ObjectPool <ISender>(options.ObjectPoolSize);

            for (var i = 0; i < udpSenderObjectPool.Capacity; i++)
            {
                udpSenderObjectPool.Push(new UdpSender(_udpSocketSender));
            }

            _packetContextObjectPool = new ObjectPool <IPacketContext>(options.ObjectPoolSize * 2);

            for (var i = 0; i < _packetContextObjectPool.Capacity; i++)
            {
                _packetContextObjectPool.Push(new PacketContext()
                {
                    Serialiser = this.packetSerialiser
                });
            }

            bytePool = new ObjectPool <byte[]>(options.ObjectPoolSize);

            for (var i = 0; i < bytePool.Capacity; i++)
            {
                bytePool.Push(new byte[options.PacketSizeBuffer]);
            }
        }