예제 #1
0
        public void init(ChannelConfig channelConfig, ExecutorPool executorPool, IEventLoopGroup eventLoopGroup)
        {
            if (channelConfig.UseConvChannel)
            {
                var convIndex = 0;
                if (channelConfig.Crc32Check)
                {
                    convIndex += Ukcp.HEADER_CRC;
                }
                if (channelConfig.FecDataShardCount != 0 && channelConfig.FecParityShardCount != 0)
                {
                    convIndex += Fec.fecHeaderSizePlus2;
                }
                _channelManager = new ClientConvChannelManager(convIndex);
            }
            else
            {
                _channelManager = new ClientEndPointChannelManager();
            }

            //初始化线程池 创建一个线程就够了
            _executorPool = executorPool;
            _executorPool.CreateMessageExecutor();
            _eventLoopGroup = eventLoopGroup;

            bootstrap = new Bootstrap();
            bootstrap.Group(_eventLoopGroup);
            bootstrap.ChannelFactory(() => new SocketDatagramChannel(AddressFamily.InterNetwork));
            bootstrap.Handler(new ActionChannelInitializer <SocketDatagramChannel>(channel =>
            {
                var pipeline = channel.Pipeline;
                pipeline.AddLast(new ClientChannelHandler(_channelManager, channelConfig));
            }));
        }
예제 #2
0
 public void init(int workSize, KcpListener kcpListener, ChannelConfig channelConfig, params int[] ports)
 {
     _executorPool = new ExecutorPool();
     for (int i = 0; i < workSize; i++)
     {
         _executorPool.CreateMessageExecutor();
     }
     init(_executorPool, kcpListener, channelConfig, ports);
 }