private void KcpSend(byte[] buffers, int length) { if (this.IsDisposed) { return; } Kcp.KcpSend(this.kcp, buffers, length); this.GetService().AddToUpdateNextTime(0, this.Id); }
private void KcpSend(KcpWaitPacket kcpWaitPacket) { if (this.IsDisposed) { return; } MemoryStream memoryStream = kcpWaitPacket.MemoryStream; switch (this.Service.ServiceType) { case ServiceType.Inner: { memoryStream.GetBuffer().WriteTo(0, kcpWaitPacket.ActorId); break; } case ServiceType.Outer: { // 外网不需要发送actorId,跳过 memoryStream.Seek(Packet.ActorIdLength, SeekOrigin.Begin); break; } } int count = (int)(memoryStream.Length - memoryStream.Position); // 超出maxPacketSize需要分片 if (count <= maxPacketSize) { Kcp.KcpSend(this.kcp, memoryStream.GetBuffer(), (int)memoryStream.Position, count); } else { // 先发分片信息 this.sendCache.WriteTo(0, 0); this.sendCache.WriteTo(4, count); Kcp.KcpSend(this.kcp, this.sendCache, 0, 8); // 分片发送 int alreadySendCount = 0; while (alreadySendCount < count) { int leftCount = count - alreadySendCount; int sendCount = leftCount < maxPacketSize ? leftCount : maxPacketSize; Kcp.KcpSend(this.kcp, memoryStream.GetBuffer(), (int)memoryStream.Position + alreadySendCount, sendCount); alreadySendCount += sendCount; } } this.Service.AddToUpdateNextTime(0, this.Id); }
private void KcpSend(KcpWaitPacket kcpWaitPacket) { if (this.IsDisposed) { return; } MemoryStream memoryStream = kcpWaitPacket.MemoryStream; if (this.Service.ServiceType == ServiceType.Inner) { memoryStream.GetBuffer().WriteTo(0, kcpWaitPacket.ActorId); } int count = (int)(memoryStream.Length - memoryStream.Position); Kcp.KcpSend(this.kcp, memoryStream.GetBuffer(), (int)memoryStream.Position, count); this.Service.AddToUpdateNextTime(0, this.Id); }