public bool SendAsync(byte[] bytes) { SendBuffer.StartPacket(); // 写入包头 SendBuffer.Buffer.WriteInt16(Packet.HEAD); // 写入包长 SendBuffer.Buffer.WriteInt32(bytes.Length); // 写入数据 SendBuffer.Buffer.WriteBytes(bytes, 0, bytes.Length); SendBuffer.EndPacket(); bool result = true; if (!mSendAsync) { int count = 0; int offset = 0; if (SendBuffer.GetFirstPacket(ref offset, ref count)) { mSendAsync = true; SendEventArgs.SetBuffer(SendBuffer.Buffer.Bytes, offset, count); result = AsyncNet.SendAsync(this); } } return(result); }
public bool SendAsync(byte[] bytes) { lock (sync) { SendBuffer.StartPacket(); // 写入包头 SendBuffer.Buffer.WriteInt16(HEAD); // 写入包长 SendBuffer.Buffer.WriteInt32(bytes.Length); // 写入数据 SendBuffer.Buffer.WriteBytes(bytes, 0, bytes.Length); SendBuffer.EndPacket(); return(SendAsync(false)); } }