internal void SendDisconnect() { if (m_Dispose) { return; } byte[] buffer = new byte[8]; ByteWriteMemory write = new ByteWriteMemory(buffer); write.Write(KcpConstants.Flag_Disconnect); write.Write(m_Conv); for (int i = 0; i < 3; ++i) { Send(buffer, 0, 8); } Flush(); }
public static int Send(byte[] buffer, Packet packet) { //消息格式 //2字节消息类型,2字节消息长度,N字节消数据 int size = CmdMsgLength + packet.Buffer.ReadableLength; if (size > buffer.Length) { throw new ArgumentException($"PacketProcessing Send error total: {size} > {buffer.Length}"); } ByteWriteMemory memory = new ByteWriteMemory(buffer); //1.写入消息类型 memory.Write(packet.Cmd); //2.写入消息长度 memory.Write((ushort)packet.Buffer.ReadableLength); //3.写入消息数据 memory.Write(packet.Buffer); return(size); }