public override void Update() { this.StartSend(); var now = TimeUitls.Now(); if (now > this.LastCheckTime) { KCP.KcpUpdate(this.Kcp, now); Service.RemoveUpdate(this.Id); this.LastCheckTime = KCP.KcpCheck(this.Kcp, now); } }
/// <summary> /// 开始发送KCP数据包 /// </summary> /// <returns></returns> public override void StartSend() { if (!this.Connected) { return; } var now = TimeUitls.Now(); while (this.SendParser.Buffer.DataSize > 0) { var offset = this.SendParser.Buffer.FirstReadOffset; var length = this.SendParser.Buffer.FirstDataSize; length = length > MaxPSize ? MaxPSize : length; KCP.KcpSend(this.Kcp, this.SendParser.Buffer.First, offset, length); this.SendParser.Buffer.UpdateRead(length); } }
/// <summary> /// 处理KCP接收数据 /// </summary> /// <param name="bytes"></param> /// <param name="offset"></param> /// <param name="lenght"></param> public void Input(byte[] bytes, int lenght) { KCP.KcpInput(this.Kcp, bytes, lenght); Service.AddUpdate(this.Id); }