예제 #1
0
        public static ReadTask New(Ukcp kcp)
        {
            ReadTask readTask = RECYCLER.Take();

            readTask.kcp = kcp;
            return(readTask);
        }
예제 #2
0
        public static WriteTask New(Ukcp kcp)
        {
            WriteTask recieveTask = RECYCLER.Take();

            recieveTask.kcp = kcp;
            return(recieveTask);
        }
예제 #3
0
        public void handleReceive(IByteBuffer byteBuf, Ukcp ukcp)
        {
            var message = _protoDecodeEncode.decode(byteBuf);
            var handler = _messageManager.getHandler(message.MessageId);

            handler.handler(message);
        }
예제 #4
0
        public Ukcp connect(IChannel localChannel, EndPoint remoteAddress, ChannelConfig channelConfig, KcpListener kcpListener)
        {
            KcpOutput   kcpOutput   = new KcpOutPutImp();
            ReedSolomon reedSolomon = null;

            if (channelConfig.FecDataShardCount != 0 && channelConfig.FecParityShardCount != 0)
            {
                reedSolomon = ReedSolomon.create(channelConfig.FecDataShardCount, channelConfig.FecParityShardCount);
            }

            var _messageExecutor = _executorPool.GetAutoMessageExecutor();

            var ukcp = new Ukcp(kcpOutput, kcpListener, _messageExecutor, reedSolomon, channelConfig);

            var user = new User(localChannel, remoteAddress, localChannel.LocalAddress);

            ukcp.user(user);

            _channelManager.New(localChannel.LocalAddress, ukcp, null);

            _messageExecutor.execute(new ConnectTask(ukcp, kcpListener));

            var scheduleTask = new ScheduleTask(_channelManager, ukcp, _scheduleThread);

            _scheduleThread.schedule(scheduleTask, TimeSpan.FromMilliseconds(ukcp.getInterval()));
            return(ukcp);
        }
예제 #5
0
 public ScheduleTask(IChannelManager channelManager, Ukcp ukcp, IScheduleThread scheduleThread)
 {
     _imessageExecutor = ukcp.IMessageExecutor;
     _channelManager   = channelManager;
     _ukcp             = ukcp;
     _scheduleThread   = scheduleThread;
 }
예제 #6
0
 /**
  * 重连接口
  * 使用旧的kcp对象,出口ip和端口替换为新的
  * 在4G切换为wifi等场景使用
  * @param ukcp
  */
 public void reconnect(Ukcp ukcp)
 {
     if (!(_channelManager is ServerConvChannelManager))
     {
         throw new Exception("reconnect can only be used in convChannel");
     }
     ukcp.IMessageExecutor.execute(new ReconnectTask(ukcp, bootstrap));
 }
예제 #7
0
 public void del(Ukcp ukcp)
 {
     _ukcps.TryRemove(ukcp.user().RemoteAddress, out var temp);
     if (temp == null)
     {
         Console.WriteLine("ukcp session is not exist RemoteAddress: " + ukcp.user().RemoteAddress);
     }
 }
예제 #8
0
 public void del(Ukcp ukcp)
 {
     _ukcps.TryRemove(ukcp.getConv(), out var temp);
     if (temp == null)
     {
         Console.WriteLine("ukcp session is not exist conv: " + ukcp.getConv());
     }
 }
예제 #9
0
 public void del(Ukcp ukcp)
 {
     _ukcps.TryRemove(ukcp.getConv(), out var temp);
     if (temp == null)
     {
         Console.WriteLine("ukcp session is not exist conv: " + ukcp.getConv());
     }
     ukcp.user().Channel.CloseAsync();
 }
예제 #10
0
        public void New(EndPoint endPoint, Ukcp ukcp, DatagramPacket msg)
        {
            var conv = ukcp.getConv();

            if (msg != null)
            {
                conv = getConv(msg);
                ukcp.setConv(conv);
            }
            _ukcps.TryAdd(conv, ukcp);
        }
예제 #11
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var  msg     = (DatagramPacket)message;
            var  channel = context.Channel;
            var  ukcp    = _channelManager.get(msg);
            var  content = msg.Content;
            User user;

            if (ukcp != null)
            {
                user = ukcp.user();
                //每次收到消息重绑定地址
                user.RemoteAddress = msg.Sender;
                ukcp.read(content);
                return;
            }


            //如果是新连接第一个包的sn必须为0
            var sn = getSn(content, _channelConfig);

            if (sn != 0)
            {
                msg.Release();
                return;
            }

            var       messageExecutor = _executorPool.GetAutoMessageExecutor();
            KcpOutput kcpOutput       = new KcpOutPutImp();

            ReedSolomon reedSolomon = null;

            if (_channelConfig.FecDataShardCount != 0 && _channelConfig.FecParityShardCount != 0)
            {
                reedSolomon = ReedSolomon.create(_channelConfig.FecDataShardCount, _channelConfig.FecParityShardCount);
            }

            ukcp = new Ukcp(kcpOutput, _kcpListener, messageExecutor, reedSolomon, _channelConfig);

            user = new User(channel, msg.Sender, msg.Recipient);
            ukcp.user(user);
            _channelManager.New(msg.Sender, ukcp, msg);

            messageExecutor.execute(new ConnectTask(ukcp, _kcpListener));

            ukcp.read(content);

            var scheduleTask = new ScheduleTask(_channelManager, ukcp, _scheduleThread);

            _scheduleThread.schedule(scheduleTask, TimeSpan.FromMilliseconds(ukcp.getInterval()));
        }
예제 #12
0
 public void onConnected(Ukcp ukcp)
 {
 }
예제 #13
0
 public ConnectTask(Ukcp ukcp, KcpListener listener)
 {
     _ukcp     = ukcp;
     _listener = listener;
 }
예제 #14
0
 public ReconnectTask(Ukcp ukcp, Bootstrap bootstrap)
 {
     _ukcp      = ukcp;
     _bootstrap = bootstrap;
 }
예제 #15
0
 public void handleClose(Ukcp ukcp)
 {
 }
예제 #16
0
 public void handleException(Exception ex, Ukcp ukcp)
 {
 }
예제 #17
0
 private void release()
 {
     kcp.ReadProcessing.Set(false);
     kcp = null;
     recyclerHandle.Release(this);
 }
 public void New(EndPoint endPoint, Ukcp ukcp, DatagramPacket msg)
 {
     _ukcps[endPoint] = ukcp;
 }
예제 #19
0
 public CloseTask(Ukcp ukcp)
 {
     _ukcp = ukcp;
 }