public static ReadTask New(Ukcp kcp) { ReadTask readTask = RECYCLER.Take(); readTask.kcp = kcp; return(readTask); }
public static WriteTask New(Ukcp kcp) { WriteTask recieveTask = RECYCLER.Take(); recieveTask.kcp = kcp; return(recieveTask); }
public void handleReceive(IByteBuffer byteBuf, Ukcp ukcp) { var message = _protoDecodeEncode.decode(byteBuf); var handler = _messageManager.getHandler(message.MessageId); handler.handler(message); }
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); }
public ScheduleTask(IChannelManager channelManager, Ukcp ukcp, IScheduleThread scheduleThread) { _imessageExecutor = ukcp.IMessageExecutor; _channelManager = channelManager; _ukcp = ukcp; _scheduleThread = scheduleThread; }
/** * 重连接口 * 使用旧的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)); }
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); } }
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()); } }
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(); }
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); }
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())); }
public void onConnected(Ukcp ukcp) { }
public ConnectTask(Ukcp ukcp, KcpListener listener) { _ukcp = ukcp; _listener = listener; }
public ReconnectTask(Ukcp ukcp, Bootstrap bootstrap) { _ukcp = ukcp; _bootstrap = bootstrap; }
public void handleClose(Ukcp ukcp) { }
public void handleException(Exception ex, Ukcp ukcp) { }
private void release() { kcp.ReadProcessing.Set(false); kcp = null; recyclerHandle.Release(this); }
public void New(EndPoint endPoint, Ukcp ukcp, DatagramPacket msg) { _ukcps[endPoint] = ukcp; }
public CloseTask(Ukcp ukcp) { _ukcp = ukcp; }